Operating System Error 5 Access Denied Microsoft SQL Server Error 5120

admin | November 29th, 2016 | SQL Server

MS SQL Server is a database management system whose function is to store and retrieve data, as per requested by a user. However, while accessing the server, users encounter one or the other error, which interrupt ongoing processes of a machine. Therefore, there is a need for having solutions by which one can instantly troubleshoot the Operating System error 5 SQL server error 5120.

operating system error 5 sql server error 5120

One such server error occurs when users try to mount the database on the SQL server i.e., Attach database failed for server. In this post, we are going to discuss all possible reasons involved in its occurrence and solutions to deal with same.

Reasons of 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. Therefore, when a user tries to connect database files to the server, it results in the occurrence of SQL server 5120 error message.

Possible Solutions to Troubleshoot Problem

There are two possible ways by which one can fix this error and they are mention below:

  • One way is to locate the directory and move MDF file (with its log file) to its original server path.

  • Another way is to add the file security permission on the drive where the server file is stored.

  1. Locate MDF File to the Server Directory:

    • Within your machine, search an MDF file, which you want to attach to the server

    • Now select the file having .mdf and .ldf file extension & then, copy or cut those files

      select mdf files

    • Now minimize current screen of the machine and open Computer or My Computer. Double-click on C: drive for further proceedings

      my computer

    • Click on Program Files from the C drive window and then double-click on Microsoft SQL Server

      microsoft sql server

    • Double-click on MSSQL 12.MSSQLSERVER >> MSSQL >> DATA

      sql data

    • Now, either press Ctrl+V or right-click on the current screen and select Paste option in order to paste the server files on its actual path

      paste actual path

    • Now launch Microsoft SQL Server Management Studio and from the left-hand side of the window right-click on Database option

      attach database

    • Click on Attach >> Add button for selecting the server file, which you want to attach

    • Navigate towards the location where the MDF file is store and select it. After selecting file, click on OK button

      press ok

    • Again click on OK button from Attach Database window and then you will be able to access database file without encountering any server error

  2. Assign Complete Security Permissions to A Drive

    With help of an Administrator Group, assign the file security permissions to the system drive with entire controls related to database files and log files. The source drive will be the one where required MDF file is currently locate. After enabling security permissions, you will easily be able to attach a database with the server.

Hit-And-Trial Workarounds to Fix Error

Following are some solutions by which one can fix Operating System Error 5 SQL Server Error 5120:

Note: A user can choose any one measure to troubleshoot the server error.

  • On Win7 machine, create a directory with name ‘ProjectData’ and set default NTFS permissions for having full control. This will enable users to read the database, but not allow any modifications to it.

Note: Verify that domain account should not directly appear in the access list

  • Copy the Adventureworks 2008LT MDF/LDF files to any other directory by using SQL Management studio for connecting a SQL server instance and then integrate security. Now take a trial to attach database

  • Follow below-mentioned instructions to fix the problem:

    1. Remove LDF file from the folder where machine saves both of the files

    2. Launch SQL Management studio and try to attach database

    3. In current window, you will encounter another list in which it is mention that ‘LDF file is not founded’

    4. Now click on LDF file for selection and hit on Remove >> OK button

This workaround might work because a copy of the LDF file may be saved somewhere on your machine.

Conclusion

The Operating System Error 5 SQL Server Error 5120 generally occurs either due to the absence of permissions or due to a wrong storage location of database log files. Therefore, 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. In addition, it is recommended to the server users that they should assign permissions to all computer drives, before performing any other workaround to fix this error.