How to fix SQL database error 5120

Introduction:

In SQL Server, users can perform multiple tasks with their databases like CRUD Operations, backup, update installation and etc. Sometimes there are also unknown errors that occur in the database. One of those errors is called error number 5120. This is the error of SQL Server Attach info number 5120; it happens because the MS SQL Server info doesn’t have the authorization to access LDF and MDF files.

Summary:

  • In this blog, I will introduce you to a complete manual solution for 5120 error.
  • Also, will be told you the detail about this error and why this error happens.
  • And how to prevent these kinds of authorization errors.

Getting started:

Sometimes, you wish to understand a lot of concerning permissions on the file, service account, etc. To access your MS SQL Server but you cannot access this due to this error. One of the scenarios has come to me from a developer who’s told me that once he attaches MDF and LDF file to the SQL instance, the attachment is successful, however, the problem was next to the information whose file is in read-only mode. This means that you cannot access your files anymore due to security authorization.

Firstly, you should try these lines:

USE [master]
GO
ALTER DATABASE [YourDatabase] SET READ_WRITE WITH NO_WAIT
GO

I hope these lines will solve this error. if you are getting still the same error like this. The alter database will modify your database. You need to specify the database and the set read_write will grant read and write permissions immediately.

SQL Database Error 5120:

Some of the common reasons for this error:

  • Can’t open the MDF and LDF physical file.
  • Maybe the filename is incorrect so renaming may fix this kind of error.
  • It can’t be open due to insufficient memory space.

These are all the major response reasons which SQL Server throws when this error occurs. The databases didn’t attach because of permissions problems. We have a tendency to solve the difficulty by granting SQL exclusive rights to the information files and unselecting the read-only attribute.

Step by Step Manual Solution to FIX ERROR 5120:

The very first steps to resolve this issue is to find your service account which could be found when you open the configuration manager tab in MS SQL Server. So, in my MS SQL, its “NT Service\MSSQL$SQL2012” for SQL Server instance. Below are the steps that how to give permission to files or folder.

  1. Place the mouse icon on the database files and right-click on these databases (MDF/NDF) file or folder and select Properties.
  2. Select the Security tab in the popup and click the Edit button while finding the appropriate solution.
  3. Then click the Add button.
  4. Enter the object name to select as NT Service\MSSQL$SQL′ and then click the Check Names button to check the validation of the name
  5. It would become MSSQL$SQL
  6. Click the OK button.
  7. Give this MS SQL service account Full Control to the file or folder.
  8. Click the OK button.
  9. Now give it a try to attach your MDF database file. This time it should work fine.

Recommendation:

If this method is difficult for you and you are not able to perform this task then, I also have another option and recommended software to recover from this error. If the above-mentioned ways do not work for you and you are still facing this file permission error 5120, then in these kinds of cases, there are only two options left to do you can either restore all important data from SQL Backup or fix it with SQL database recovery software.

Stellar Repair for MS SQL

Stellar Repair for MS SQL is a professional software used to repair corrupted database it does the following:

  • Recover every info file MDF and NDF.
  • The Compatibility level of this software is very convenient with all versions of MS SQL Server.
  • Also, they have a very user-friendly interface while the user interacts with the software to recover their lost data.

You can download the software from here:

Conclusion:

In this blog, we studied that when an MS SQL Server’s user can face some issues and want a single solution for every problem. We studied about step by step guide to solve this problem manually. When you know the main reasons behind this kind of error, you can avoid Microsoft SQL server error 5120. In some cases, it can be solved by adding permissions to a drive or by allocating database files to its original location. And, if things don’t work in manual ways then a user can opt for an alternative technique. This technique is to buy a third party software like Stellar Repair for MS SQL.

Leave a Reply

Your email address will not be published. Required fields are marked *