views:

37

answers:

1

When I right click on "databases" in Sql Server 2005 Management Studio and then > Attach... > Add I get the following error:

C:\Documents and Settings\Administrator\My Documents\SQL Server Management Studio\ Projects\Path\To\MDF\And\LDF\Files\ cannot access the specified path or file on the server. Verify that you have the necessary security privileges and that the path or file exists.

The answer is easy - the MDF and LDF files where removed when Nant (by way of my dev machine) issued a drop command.

But, after replacing the MDF and LDF files, I want to reattach the database but the above error keeps coming up when I select "Add".

Also, I have already "unattached" the database in question and it no longer appears on the left under "databases".

I have tried to replace a copy of the MDF and LDF files in the folder being referenced and that didn't work.

Any ideas as to how to gracefully get rid of this error?

+1  A: 

Verify that you have the necessary security privileges and that the path or file exists.

Grant full read-write privileges on the MDF and LDF to the SQL Server service account:

cacls C:\...Path\To\Files\ /E /T /G SQLServerMSSQLUser$<hostname>$<servicename>:F

where <hostname> is your SQL Server hostname (machine name) and <instancename> is the SQL Server instance name (MSSQLSERVER for default instance).

Remus Rusanu
Thanks. I did that by right clicking on the files and adding the appropriate permissions. I then tried to do an "Add" database and got the same error. Do you really think that permissions is the problem? This whole mess started when my dev env ran a script that dropped the database and now I can't add a (or any) new database without seeng the "Veryify that you have the..." error. This error happens regardless of whether or not the MDF and LDF files are present. More thoughts?
Code Sherpa
I really do think permissions is the problem.
Remus Rusanu
I got the solution by using the "locate file" dialog that popped up after the error dialog appeared. I am not sure why I was avoiding this originally. Anyway, I am guessing SQL reset the appropriate permissions on the files when I selected them using the dialog so I credited your answer. Thanks.
Code Sherpa