How to Fix Microsoft SQL Server, Error: 5120 (Access Denied)

  • Written By  

  • Updated on February 6th, 2018

SQL (Structured Query Language) is a standardized programming language that is used for managing interpersonal databases and performing several operations on the data in them. MS SQL Server also works to store and retrieve data, as per demand by a user. However, while accessing the server, users encounter one or the other error, which interrupt ongoing processes of a machine.
SQL Server error 5120 is yet another error that is very common. Therefore, there is a need for having solutions by which one can instantly troubleshoot the Operating System error 5 SQL server error 5120.

This 5120 Error code ascends, when the version in which it is running on the SQL server service does not have the right to use MDF and LDF files of a database. Subsequently, in this post, we will discuss the solution to fix this error message.

Reasons for Operating System Error 5 SQL Server Error 5120 Occurrence

  1. The main reason is that MDF database files are not located at their accurate location. It means that an MDF file of the server might be store in some other drive of a computer.
  2. There is one more reason for such error occurrence i.e., system drives might not be having permissions to store the server file within them. Thus, when a user tries to connect database files to the server, it results in the occurrence of SQL server 5120 error message.

How to Fix Attach SQL Database Error 5120

Create two users account such as SQLAdminOne and SQLAdminTwo on the SQL server and then follow the steps shown below to solve the error 5120 in SQL server:

  • Create A New Database: Follow the below-mentioned steps to generate a new database such as Test:
    CREATE DATABASE [Test]
    CONTAINMENT = NONE
    ON PRIMARY
    (NAME = N’Test’, FILENAME = N’D:\SQLDATA\MSSQL13.MSSQLSERVER\MSSQL\DATA\Test.mdf’)
    LOG ON
    (NAME = N’Test_log’, FILENAME = N’D:\SQLDATA\MSSQL13.MSSQLSERVER\MSSQL\DATA\Test_log.ldf’)
    GO
  • Check Test File Permission For MDF and LDF: Browse the location of MDF and LDF files and then right-click on the file >> Properties >> Security

  • SQLAdminOne Detaches Test DatabaseRight-clickon the Test database>> Tasks >> Detach
  • Check Test File Permission for MDF and LDF Again: Test database MDF and LDF files permissions have changed and full permission are granted to SQLAdminOne only.

  • SQLAdminTwo Tries To Attach Test Database: When SQLAdminTwo tries to attach the Test database SQL error code 5120 occurs due to the limited permission on the database files
  • Grant Full Permission On both MDF and LDF Files of Test Database: Follow the below-mentioned steps to grant the full permission on the Test database file:
    • Right-click on the Testdatabase file and then select Properties
    • Now, click on Securitytab and then click on Edit button
    • Click on the Addbutton and then enter the object name to select as NT Service\MSSQL$SQL2013. After that, click on Check Names button and then click on OK
    • Now, give this account Full Controlto the file and then click on OK button

  • Reattach Test database: SQLAdmin Two become successful to attach the Test database.

What can you do when these steps does not work?

If these steps fail to fix your SQL Server Database Error 5120, it might be major problems within your SQL database. In condition, either restore entire data from SQL Backup or repair corrupted SQL Database using best SQL recovery software.

Conclusion

After reading this blog the reader and the user will get complete knowledge about how to fix the Operating System Error 5 SQL Server Error 5120. Generally this kind of error occurs either due to the absence of permissions or due to a wrong storage location of database log files. Therefore,in order to fix this issue users need to move database file (or MDF file) to its original location or will have to add legal permissions to a computer drive.

Rate this post

About The Author:

Rohan Wiese is a Technical Writer at Aryson Technologies. He is an expert Email Forensic, Cloud Computing, and a passionate nerd with over 10 years of experience in technical content writing. He writes about Cloud Migration, Database Recovery, Email Backup, Windows, Mac, and Tech.

Related Post

Aryson Technologies

united states

2880 Zanker Road, Suite 203, San Jose, CA - 95134, USA

india

A-58 , 2nd Floor A Block Sector 57, Noida, Uttar Pradesh 201301

© Copyrights 2014-2024 by Aryson Technologies Private Limited - All Rights Reserved