Getting Error While Attaching the Database in SQL Server

Resolved SQL
CM
Community Member
December 25, 2015
6 replies
1,100 views
Reviewed by moderators

I have a MDF file and no associated LDF file for a database created in MS SQL Server 2008. When I am trying to attach the MDF file to a different SQL Server, then I am facing error.

Unable to open the physical file "D:\Database2. mdf". Operating system error 5: "5(Access is denied.)". (Microsoft SQL Server, Error: 5120)

6 Answers
Accepted Answer
Verified by Edwin J. Hoffer, Expert · Reviewed December 2015

You need to provide the modify privilege to the SQL Service accounts to the folder C:\ArrowSQL\Arr@Data and then attach the db, it will attach without privilege error!nNow, if you are using windows 7. Open the SSMS like this - Right click -> Run as Administrator and then login in windows mode and try to attach the database files.

When I followed the instructions given by you, the same error prompted that's why I am unable to attach the. mdf file. What may the possible reasons for this error?

Please make sure that. mdf file and. ldf file on the same drive

    n
  • Go to the folder where mdf file is stored.
  • n
  • Select file
  • n
  • Right click on the file
  • n
  • Give full permissions to file for logged in user Security. 
  • n
nnn

What may the possible reasons for this error?
nnThe problem of operating system error 5(access is denied.) is due to lack of permissions for SQL Server to access the Primary (. mdf) & Log (. ldf) files. nnAnd to fix this error nChange the MSSQLSERVER service startup user account, with the user account who have better privileges on the files and then try to attach the database. nOr nStartup with windows administrator account, and open SQL Server with run as administrator option and try to login with windows authentication and now try to attach the database.

Thanks Andrew and Michael for your clarifications, I have fixed my problem