Home > SQL Errors > SQL Error – Unable to open the physical file. Operating system error 5: “5(Access is denied.)”

SQL Error – Unable to open the physical file. Operating system error 5: “5(Access is denied.)”

October 25, 2016 Leave a comment Go to comments

Today I Detached a Database from SQL Server and moved the mdf/ldf files to an another drive, but while Attaching those files from the new location I got error below by using following script:

USE [master]

( FILENAME = N'E:\NewDB\NewDatabase.mdf' ),
( FILENAME = N'E:\NewDB\NewDatabase_log.ldf' )

Msg 5120, Level 16, State 101, Line 4
Unable to open the physical file “C:\NewDB\NewDatabase.mdf”. Operating system error 5: “5(Access is denied.)”.
Msg 1802, Level 16, State 7, Line 4
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

Well the error clearly mentions that the error is due to the limited access of Service Account by which SQL Services are running, it doesn’t have access to the new folder location where the database mdf/ldf files are moved.

So, you just need to go to the new folder location, check the folder Properties and go to Securities tab, select the Service account and click on Edit button.

On the new Security popup window click under the Allow checkbox for Full Control permission.


Now execute the above Attach script and the Database will be attached without any issues.


Categories: SQL Errors Tags:
  1. Ahmad Awad
    March 14, 2019 at 1:48 am

    Thanks Manoj

  2. zulfi
    August 22, 2019 at 1:58 am

    it helped. thanks

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: