• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

sql mdf file attach error

I have a set of mdf and ldf files given to me by a client. I open sql server express management studio and try to attach the mdf files as a database. I recieve an error "Unable to open physical file blah\blah\blah operating system error 5: (access is denied) (Microsoft SQL Error: 5120)

The file is not open in any other program, and all permissions are applied to the file.

Why would this be happening, how to fix?

2 Solutions
Raja Jegan RSQL Server DBA & ArchitectCommented:
Make sure that the startup account of SQL Server services has access to the folder and mdf and ldf files.
If so, then copy mdf and ldf files to Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

and then try attaching the file which should work.
In administrative tools > services > try to run the MSSQL service under local system account it should work.

Use the below script to find the sql service account


Code Snippet

declare @sqlser varchar(20)

EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SYSTEM\CurrentControlSet\Services\MSSQLSERVER',

@value_name='objectname', @value=@sqlser OUTPUT

PRINT 'Account Starting SQL Server Service:' +convert(varchar(30),@sqlser)



After getting the service account try the below steps to provide privilege


      Right click on the folder C:\ArrowSQL\Arr@Data and click on properties
      Click on security tab
      Click on Add button and add sql service account
      Provide modify privilege and click ok
      Verify both mdf and ldf have modify privilege
      Attach the db!

or  Refer  http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/9e563890-e35f-4524-82b9-3cca08fec5ed
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

change the security of the mdf file and ldf file received. authorize your current user with full access.
you may need to check whether you have already got same database running.

when you re-attach, just open the options tab to see the path is correct or not, maybe the Drive letter need to be changed.
MatthewOsoskyAuthor Commented:
mdf AND ldf solved it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now