9

SQL Error – Unable to open the physical file. Operating system error 5: “5(Acces...

 3 years ago
source link: https://sqlwithmanoj.com/2016/10/25/sql-error-unable-to-open-the-physical-file-operating-system-error-5-5access-is-denied/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

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]
GO
CREATE DATABASE [NewDatabase] ON
( FILENAME = N'E:\NewDB\NewDatabase.mdf' ),
( FILENAME = N'E:\NewDB\NewDatabase_log.ldf' )
FOR ATTACH
GO

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.

attach-db-access-denied

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



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK