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.
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.
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.
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.
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.
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
Now minimize current screen of the machine and open Computer or My Computer. Double-click on C: drive for further proceedings
Click on Program Files from the C drive window and then double-click on Microsoft SQL Server
Double-click on MSSQL 12.MSSQLSERVER >> MSSQL >> 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
Now launch Microsoft SQL Server Management Studio and from the left-hand side of the window right-click on Database option
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
Again click on OK button from Attach Database window and then you will be able to access database file without encountering any server error
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.
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:
Remove LDF file from the folder where machine saves both of the files
Launch SQL Management studio and try to attach database
In current window, you will encounter another list in which it is mention that ‘LDF file is not founded’
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.
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.