1

I have SQL Server Express installed on my local machine. When I try to attach a database file, it's giving me the following error

Unable to open physical file "C:\Adventures2012_data.mdf. Operating system error 5: 5 (Access is denied) (Microsoft sql server error 5120)

Please let me know how to fix this??

2
  • 1
    Access is denied is quite a self explanatory error. Sep 2, 2013 at 18:28
  • move the file to some other folder having a full permission or execute permission for the SQL service account and then try to attach file. Sep 3, 2013 at 5:20

3 Answers 3

4

The minimal permissions needed to attach a database file is 'full control'. If you want to attach the database using SQL Server Management Studio, the account running SSMS must have full control on both the database MDF and LDF files

To grant privileges to files:

  1. Right click the file in Windows Explorer
  2. Open the Security tab
  3. Click Edit
  4. Click Add and add the SSMS account
  5. Grant Full control
  6. Go to SSMS and try to attach the file again

You can copy the file to another folder, to avoid C root, you might not have enough permissions there

1
  • Worked for me tooooo. One addition from my end: I have multiple databases inside a folder so I Right clicked on the Folder instead of file and follow the above process. All databases inside that folder are working now.
    – MaxPayne
    Oct 27, 2015 at 7:03
0

1) right click the .mdf file 2) Propertiest 3) Security 4) edit 5) add 6) Advanced 7) find now 8) everyone 9) okay 10) okay 11) Full controll 12) okey 13) okey 14) right click sql server management studio 15) run as administrator 16) Then Attach.

Good luck

-1

I had the same problem with the AdventureWorks database. I changed the directory from C:\ to E:\, and then right-clicked on the AdventureWorks database, selected Security, and granted the Full Control permission to your local users. Finally, you can run SQL Management Studio as Administrator, and attach your database.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .