Unable to open the physical file "xyz.mdf". Operating system error 5: "5(Access is denied.)".

I downloaded some project from here, this included some test MS SQL Server database file called 'SchoolDB.mdf'. I tried to attach it in SQL Server Management Studio 2017.





SSMS throws error as -





Attach database failed for Server 'VSPLBLRLT0231'.  (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=14.0.17285.0+((SSMS_Rel_17_4).180821-0238)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

Unable to open the physical file "D:\xyz@xyz\LearnPlace\entityframeworktutorial.net\EF6-DBFirst-Demo-master\EF6-DBFirst-Demo-master\EF6DBFirstDemo\SchoolDB.mdf". Operating system error 5: "5(Access is denied.)".

CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (Microsoft SQL Server, Error: 5120)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=14.00.1000&EvtSrc=MSSQLServer&EvtID=5120&LinkId=20476

Got solution from here








Now you'll be able to attach .mdf file in SSMS. But the problem is database name having full file path. You can simply rename that in SSMS.



 

Comments

Popular posts from this blog

This database file is not compatible with the current instance of SQL Server.