-->

Can't attach ASP.NET database to SQL Server Ma

2020-07-10 20:08发布

问题:

I have an ASP.NET MVC3 project that has a database. I want to attach that database to SQL Server Management Studio.

In SQL Server Management Studio, I right click Databases, then click Attach, then click Add and it shows the folder/file selection dialog.

The problem is it won't let me explore any folder inside my user account folder (c:\users\Bob). I can see the Bob folder but there is no + to expand, and shows no child items (even though I know there are files in my windows user folder). Why isn't it letting me explore there?

SQL Server Management Studio is version 11.0.21 (SQL Server 2012)

I have tried selecting All files from the filter dropdown instead of *.mdf, but no files show.

回答1:

Two other things to note:

  1. The 'attach' looks in the default 'DATA' directory that is configured for the server as shown below.
  2. You may or may not have an *.ldf file. When you try to attach, SSMS thinks you have one, so if you do not, you will have to click 'remove' on that file in the list of files to attach.



回答2:

Although this question is two years old, I just had the same problem.

I solved it by giving MS SQL Server Express access to my user folder.

Open Windows Explorer and find your user folder, Right click and click Properties, then the Security tab.

I had to add the virtual user that SQL server uses to access files, so clicked on Edit, then in the next window, clicked Add.

You won't know the virtual name to use, so just click Advanced, then Find Now and Windows will show a list of all users. Scroll down and find something like :

SQLServerMSSQLUser$

(you will have to drag the separation in bar (in the column header) to the right in order to see the full names)

Back in the Permissions window, give the SQL user Full Control.