SQL Server Error: Unable to open the physical file - Operating system error 5: "5(Access is denied.)"

← PrevNext →

I am guessing, you have migrated from an old operating system to a new one and left behind your previous version of SQL server to migrate to a new version of SQL server database. In addition, while attaching your old database on a new platform using SQL server management studio, you hit a roadblock in the form of an error. It says Unable to open the physical file – Operating system error 5.

Unable to open physical file (SQL Server Error)

It clearly points to a message, Access is denied. We have tested this scenario on "Windows 7" using SQL Server 2008 R2 and SQL Server 2012 Express database. The database, which we are trying to attach, is from a previous version.

It is clearly an issue with permissions granted to users and administrators accessing the computer. The administrator by default will have full control on files and folders, whereas users may or may not have the necessary permissions.

If you have logged in to your computer as an "USER" and not as an ADMINISTRATOR then you need to follow these steps to fix the problem.

01) Right click the ".mdf" file and choose "Properties".

02) In the properties dialog box, select the Security tab, which will show you a list of Group or user names. Each group and user names in list will have specific "permissions" assigned to them.

03) Click the "Edit..." button, which will open the "Permissions" dialog box. You need to find Users (… from the list and select it by clicking it.

04) You can now either "Allow" or "Deny" necessary permissions to the users according to their privileges. We suggest you check the option Allow for "Full control" and click the "Apply" button.

05) Repeat the same procedure with the ".log" file too. Both ".mdf" and ".log" files should have similar permissions.

06) Finally try to attach the database on your new SQL server database.

Properties and Permissions Dialog Box

Conclusion

This is not a very serious issue and can be addressed and solved with ease, but sometimes these little errors does take away precious time and can also be frustrating while migrating from an older platform (version) to a newer one.

🙂

← PreviousNext →