SQL Server Error 5120 - failed to attach .mdf file

Jason Clark picture Jason Clark · Dec 25, 2015 · Viewed 33.5k times · Source

While attaching my .mdf file on my SQL Server database I am getting below error message:

Msg 5120, Level 16, State 101, Line 1 Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA' Operating system error 5: "5(Access denied.)".

Error Message I don't have my .ldf file of associated database. How can I attach my .mdf file without .ldf file? I am using SQL Server 2014.

Answer

maneesh picture maneesh · Feb 27, 2017

GO to the folder where you have stored MDF file. You can either do this to the entire folder or the MDF/LDF individually. Select file/folder-> Right click ->click on "Security". Then "Edit'. If you dont have OWNER RIGHTS listed Click ADD and search for it, click OK. enter image description here

And then give Full Control to user OWNER RIGHTS. enter image description here

permission for mdf file