Attaching Database – Unable to Open Physical File (Access is Denied)

Msg 5120, Level 16, State 101, Line 1 Unable to open the physical file "\\servername\sharename\filename.mdf". Operating system error 5: (Access is denied.).

This is more often than not an issue with permissions and windows level security.

The permissions on the S:\ and T:\ seem a bit odd in that the server Admins overall have full control on the drives but not of some individual DB’s within the drives. However, when looking at individual files within the S:\ Drive I can see that some of the data files don’t have the correct permissions filtered down to them.

The reason additional permissions are needed is when a DB is reattached it inherits the Owner as the person attaching the file.

To fix, I did the following:

Added the Administrators Group to the file security permissions with full control for the Data file (S:\) and the Log File (T:\).

Attached the database and it works fine.

I did some more digging and think I may have resolved the security problem without manually editing each file


Check the tick box and then click ok.


Click Yes and this will propagate permissions on to each file.

After I did this, I was able to attach databases without any issues.


13 Responses to Attaching Database – Unable to Open Physical File (Access is Denied)

  1. Amrit says:

    Great. It worked for Me…

  2. says:

    It was useful for me…

    Thank you.

  3. rick says:

    I have attached/restored my database fine on sql 2008. However, when launching client software to access the database, a message came up: “Write access is denied to the database SERVERNAME\DATABASENAME. You will be limited to read-only access without any update notifications.” I ensured all accounts have full access to the database but to no avail on client side. Any suggestions?

  4. Giovanni says:

    I change logon user on mssqlserver service from “Service NT\MSSQLSERVER” to “local Service” and I resolve problem

  5. Pingback: Open Pst File Access Is Denied |

  6. Pingback: How To Fix Fcleaner Unable How To Open Database File Errors - Windows Vista, Windows 7 & 8

  7. Pingback: How To Fix Delete File Failed Code 5 Access Denied Errors - Windows Vista, Windows 7 & 8

  8. Pingback: Confluence: McCormick

  9. srihari Muppalla says:

    its very useful for me thank you.

  10. Thanks for its post. Congratulations! Att

  11. Thanks.. This helped me

  12. ahammed says:

    guys select the folder that was placed in the c drive and on the folder rt-click and properties sercurity tab choose permisons and make the check box tik and now in sql server ms choose new query……type code

    CREATE DATABASE AdvantureworksLT2008 ON
    (FILENAME = ‘C:\Advantureworks\AdvantureworksLT2008_Database\AdventureWorksLT2008_Data.mdf’),
    (FILENAME = ‘C:\Advantureworks\AdvantureworksLT2008_Database\AdventureWorksLT2008_Log.ldf’) FOR ATTACH;

    it works for me

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: