Tag Archives: SQL

Attach SQL .MDF database that is stored in user area

I’ve been working on Visual Studio 2010 projects with local databases recently, and had an issue with different SQL Server versions. To overcome the problem, I attach the MDF file to the correct SQL Server version instance, open it, then detach and return to Visual Studio.

However, when trying to do this, I’ve encountered another problem, in that when browsing for my MDF file (which is stored in my App_Data Folder in my project, which is in my user area – C:\users\me\….) , I can’t get any further than my name.Weird, because I’m running SQL Management Studio as Administrator (Windows 7) and using my account to log into it. I thought this was weird: I’m logging in as me, so why can’t I access MY files!

After some searching on forums etc, I found that I needed to add my username (whether it is local or domain) as a sysadmin on the server instance (Security > Server Roles in Management Studio). I tried this and id didn’t make any difference. What I then found was the the account that the SQL server service runs as is important in this case too. Here is the key: Change the logon account for the SQL Server service to LOCAL SYSTEM. When I installed the instance, NETWORK SERVICE was used, it obviously doesn’t have all the rights you need.

Once that’s done, restart Management Studio, and you’ll find no problem browsing where you like to attach MDF files.

Hope this helps someone else.