Resolve Microsoft SQL Server Error 5120 Attach Database Problem

Admin | Modified: 2020-05-05T10:56:21+00:00 | SQL Server

Microsoft SQL Server is a widely used database management system. The primary function of this application is to store and retrieve the data requested by the SQL user. And SQL (Structured Query language) is used to perform operations on the data. But sometimes SQL database users encounter one of the common SQL Server error 5120 attach database problems. Let us take an example of Query asked by the user in one of the forum website. It will help us to understand the situation in a better way.

Please help! While attaching the database with the MDF and LDF file. It shows an error like this Unable to open the physical file “D:\mydatabase.mdf”. Operating system error 5: “5(Access is denied.)”. (Microsoft SQL Server, Error: 5120)”. Can anyone provide me the reasons for this error? Also, suggest the best possible way to resolve this problem. Thanks!”

Basically, this problem occurs when Microsoft SQL Server database users don’t have the authorization to access the MDF and NDF file of the database. Before proceeding to the solution part let us first discuss the various causes of this problem.

Also Read: How to Recover deleted database in SQL Server Without backup.

Reasons Behind Microsoft SQL Server Error 5120 Attach Database Problem 

1. If your MDF files are not at the accurate location or MDF database files are stored in some other drive of the computer.

2. In case if you are not running your Microsoft SQL Server management studio with admin rights.

3. If system drives don’t have the permission to store the server file within them. Then also, in that case, it will show the error 5120 in SQL Server 2017, 2016, 2014, 2008 R2, 2008, and 2005.

Smart and Efficient Solution to This ProblemSQL Server Error 5120

If you are facing Microsoft SQL server error 5120 attach database problem, I suggest you restore the entire data from the backup or repair corrupt SQL database MDF file. If you want to recover the data without backup, you can take the help of Recover SQL Database Software. It repairs corrupted MDF and NDF files files and export them to the SQL database. The software allows the user to recover the deleted database objects such as Tables, stored procedure, functions, triggers, views, etc, Also, this software is compatible with SQL Server 2019 and its below version.

Download Now Buy Now

Follow the Steps to Recover SQL Database without backup

1. Install the Software on your machine. Click on Open and Browse the MDF file from your system.

Recover SQL Database

2. Now choose the Scan Mode, and select the SQL Server version, The user can select recover deleted objects option to view deleted objects in red color.

Recover Corrupt SQL Database

3. Click on the database objects to preview SQL database items.

Recover Deleted Database objects

4. Click on the Export button to export the MDF file data to the SQL Server Database.

Restore SQL Server Database

Conclusion

In this article, we have discussed the solution to SQL server error 5120 Attach Database error problem faced by the users. Also, we have given various reasons for this problem. To resolve this issue the user can take the help of a professional tool. It is an advanced and standalone solution to resolve this problem.

Frequently Asked Questions

How to find the location of the MDF file in SQL Server 2016?

The default MDF file location for SQL Server 2016:
C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\Tech.mdf

Why I am not able to access or open MDF file?

If you cannot access the MDF file, your file may be damaged. To fix this problem, you need to repair corrupted MDF file and then easily access it in the SQL Server database.