Fix SQL Server Error 5120 Access Denied: Fix It Now
User Query: “I’m trying to attach a database file in SQL Server. But I keep getting this message: Msg 5120, Level 16, State 101: Unable to open the physical file ‘…mdf’. Operating system error 5: (Access is denied.). My permissions seem okay. How can I fix SQL Server Error 5120 quickly and safely?”
Summary: When you work with SQL Server, you attempt actions like attaching a database, restoring a database, or starting the server. You might run into Error 5120. This error means SQL Server cannot open the database file — often due to permission or file-access issues. The full message usually says something like:
Unable to open the physical file “C:\…\mydatabase.mdf”. Operating system error 5: “5(Access is denied.)”. In this blog, we’ll explore the causes of this error and give you straightforward steps to fix it. Additionally, you can use the DRS SQL Recovery Tool for a quick and hassle-free recovery.
What Is MS SQL Server Error 5120?
Error 5120 occurs when SQL Server tries to open a data file (.mdf) or log file (.ldf) and fails because the operating system denies access. This can happen when you attach a database, restore one, or move files around. Because the engine cannot get the needed file permission, the operation fails.
Common Causes of Error 5120
Here are the most frequent reasons for this error:
- The SQL Server service account does not have sufficient file system permissions on the data/log files.
- The files are stored on a network share where permissions are stricter.
- The files may be read-only, or the folder may be blocked by OS security.
- Moreover, you used a manual file move/detach, and the permissions were not reset correctly.
Manual Methods to Fix SQL Server Error 5120
Before you jump into fixing the error manually, it’s important to understand that this issue is mainly related to file permissions. So, the solution focuses on giving SQL Server the correct access rights to open the database files. Below are some reliable manual methods you can try to fix Error 5120 safely and effectively.
Method 01: Grant File Permissions to Fix SQL Error 5120
- Firstly, find out under which account the SQL Server service is running (use SQL Server Configuration Manager).
- After that, right-click the database file (.mdf/.ldf) → Properties → Security tab.
- Then, click Edit and choose Add, then enter the SQL service account name (e.g., NT SERVICE\MSSQLSERVER).
- Now, give it Full Control, then apply the changes.
- Further, try attaching or restoring the database.
- Lastly, this method usually resolves the error instantly.
Method 02: Run SQL Server Management Studio to Fix Error Code 5120
- Sometimes, permission issues arise because SSMS runs without admin rights. Close SSMS.
- Now, right-click the SSMS icon → select Run as administrator.
- Afterwards, try attaching the database again.
- This grants temporarily elevated privileges to complete the operation.
Method 03: Move Database Files to a Local Folder
If your .mdf or .ldf files are located on a network path or shared drive, SQL Server might fail to access them.
- Start by moving both files to a local folder, such as C:\SQLData\.
- Assign the correct permissions (as shown in Method 1).
- In the end, attach the database again.
Limitations: Manually Fix SQL Server Access Denied Error 5120
Here are some common limitations of fixing SQL Server Error 5120 manually:
- Requires technical knowledge of SQL Server permissions and file access rights.
- A small mistake in file ownership or permissions can make the database inaccessible.
- Doesn’t work if the database file is corrupted or partially damaged.
- Time-consuming when dealing with multiple databases or large files.
- Furthermore, no guarantee of data recovery if the error is caused by file corruption.
Professional Tool to Fix SQL Server Error 5120
If your SQL file is severely corrupted, you can use the DRS SQL Recovery Software. It helps to Repair Corrupted SQL databases, including tables, procedures, triggers, and more, with no data loss. You can preserve original data formatting, structure, and metadata during the entire recovery. With its simple and user-friendly interface, every user can easily use it without needing technical knowledge. Apart from that, this tool is highly compatible with all Windows and Mac versions.
One-Time SQL Database Repair Service
If you don’t want to install the software, DRS offers a one-time database recovery service. Their certified experts safely scan, repair, and restore your SQL database without requiring your full server access. It’s a perfect choice for businesses that prefer a quick, hands-off solution.
Simple Steps to Repair Corrupt SQL Database Files:
- Download and install the DRS SQL Recovery Tool.

- Click on Open and add the corrupted SQL files.

- Then, choose the Recovery Mode & other options. Click Ok.

- Now, you can preview all the recovered SQL data.

- Lastly, click Save and choose a different Saving Format from the list.

Conclusion
SQL Server Error 5120 (Access Denied) is a common yet fixable problem. It usually appears when SQL Server lacks permission to access database files. You can resolve it by granting full permissions, running SSMS as admin, or moving files to a local directory. If the database remains inaccessible or is corrupted, the DRS Database Recovery Tool provides a secure, automated fix that restores data without any loss.
Frequently Asked Questions
Ans: It’s an “Access Denied” error that appears when SQL Server can’t open database files (.mdf or .ldf) due to missing permissions.
Ans: The error occurs when the SQL Server service account doesn’t have permission to access or modify the database files.
Ans: Yes, moving the files to a local folder with proper permissions often resolves the issue, especially if they were on a shared or restricted drive.
Ans: No, the error itself doesn’t delete or damage data; it only prevents access. However, if corruption occurs, you can use the SQL Recovery Tool to recover data safely.
About The Author:
I, Aaradhya Jain, a technical content writer at DRS Solutions, specializes in delivering clear, practical guides on data management, migration, and recovery tools. With a detail-oriented and user-first approach mindset, I transform complex processes into actionable insights for IT professionals and decision-makers.