Tuesday, March 27, 2012

Can't Attach to DB File using SSMS

Hi all,

I have "SQL Server Express" as well as SSMS-E installed on the same machine. I am trying to get SSMS-E to connect to a database (i.e., an .MDF file) that resides in a folder on the desktop.

After establishing a connection to my "SQL Server Express" instance within SSMS-E, I right-click on "Databases", in the "Object Explorer" window and select "Attach..." and click the "Add..." button. The resulting dialog box opens in the directory:
"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" where I see several MDF files. But as I said, my MDF is not in this directory - it's on the desktop.

If I try to navigate to the proper directory on the desktop I see no MDF files. In fact, I cannot even navigate past my username -- that is, I cannot even navigate to the desktop, let alone folders on the desktop. I don't know why.

Of course I *could* put the MDF file in the SQL-E approved directory but shouldn't I just be able to navigate to it using SSMS-E? Incidentally, I *AM* able to connect to the database on my desktop if I use Visual Studio and I specify "UserInstance=true". Not specifying "UserInstance=true" results in this error:

An attempt to attach an auto-named database for file C:\Documents and Settings\Robin\Desktop\MyCompany.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Can someone explain what might be causing the problem with SSMS-E, and, for that matter, why it's necessary to specify "UserInstance=true" in Visual Studio?

Thanks so much. I hope these are not too many questions.

Robin

You are attempting to attach a file that is located in a 'protected' storage area -specifically your private 'Desktop'. That file would not be available to other users of the computer. You can attach it to a user instance since that user instance will be restricted for your use only and other users could not access it.

If you want to attach the file to the server, move the file from your 'Desktop' to a storage area accessible for all users of SQL Server.

No comments:

Post a Comment