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??

Sohail
  • 391

3 Answers3

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

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.

Canadian Luke
  • 24,640