Table of Content
    SQL Database Repair

    How to Fix ‘Operating system error 5: “5(Access is denied.)” in MS SQL Server?

    Table of Content

      Summary: The error “Unable to open the physical file” in SQL Server usually occurs due to lack of permissions to create the database. In this post, we will mention the solutions to fix this SQL Server error. In addition, we will mention a SQL repair software that can help recover database in case it gets corrupt or damaged.

      When trying to create a database in SQL Server, you may encounter an error, saying “Unable to open the physical file.” This prevents you from creating the database.

      The complete error message looks like:

      Msg 5120, Level 16, State 101, Line 1

      Unable to open the physical file “R:\productions\stellar_database.mdf”. Operating system error 5: “5(Access is denied.)”.

      Msg 1802, Level 16, State 7, Line 1

      CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

      The access denied error means that the user creating the database does not have permissions to create files in the folder.

      Solutions to Fix the Error “Operating system error 5: “5(Access is denied.)” in SQL Server

      You can try the following solutions to resolve this SQL Server error.

      1. Check and Grant the Required Permissions

      You need to first check that the user has the required permissions.

      For this, go to Windows Explorer, right-click the production folder, and select Properties.

      Select properties in windows explorer

      Verify if the user executing the T-SQL statement to create the database has permissions to the folder.

      database permissions for administrator

      If not, press the Edit button. If the user is not in the list, press the Add button to add the user.

      Add user in providing access

      You can enter the object name. You can use the Check Name option to verify if you entered it correctly.

      Adding object name in select user/groups

      If you do not know the name, press the Advanced button to search for the user’s name.

      select advanced button for searching user group

      Write your query with the start name or description. In Object Types, you can filter to look at users only. In Locations, you can select a computer or an Active Directory domain.

      Filter from Specific location

      Once added, make sure to provide Modify permission.

      Modifying Permissions

      Note: If you do not have permission to grant permissions for the folder, you can ask the system administrator to grant the required permissions.

      2. Run as Administrator

      Another common problem is that you do not have enough permissions because you are not running the SQL Server Management Studio (SSMS) as an administrator. In this case, the solution is very simple.

      In the Windows menu, look for the SSMS, right-click on it, and select the option Run as administrator.

      Run as Administrator

      What to do if your database file is damaged or corrupted?

      Your database file may get damaged or corrupted due to hardware problem, natural disaster, virus/malware attack, or any other problem. In such a case, you can restore the database from the backup.

      If you do not have a current backup, then you can install specialized software to repair the corrupt database. One such SQL repair software is Stellar Repair for MS SQL. This software is created exclusively to fix corrupt or damaged SQL databases.

      Using the software is also simple. You just need to provide the name of the database file(s) and the software will fix it for you.

      Let’s see how it works.

      Before proceeding, bring the database offline. Once it is offline, create a copy and work with the copy. This way you will have a backup, in case something goes wrong.

      Now, launch the software and click Browse to select the database file.

      Optionally, you can use the Find button to find the database file.

      Selecting database in Stellar Repair for MSSQL

      After selecting the database file, press the Repair button to repair your database.

      Browse to find database for repair

      Once repaired, you can save the data. Press the Save icon. You can create a new database or replace the existing one.

      Saving database

      In addition, you can save the tables’ data and views in other files, like Excel, CSV, and HTML.

      Saving database in other formats

      If everything goes fine, you will be able to recover your data.


      In this post, we learned how to fix the error “Operating system error 5: “5(Access is denied.)” in SQL Server. The main reason for this error is the lack of permissions. In this case, you need an administrator or a user with privileges to provide permissions to modify files in the folder. In addition, we learned how to fix a damaged database using Stellar Repair for MS SQL.

      Was this article helpful?

      No NO

      About The Author

      Daniel Calbimonte linkdin

      Daniel Calbimonte is a Microsoft Most Valuable Professional, Microsoft Certified Trainer, and Microsoft Certified IT Professional for SQL Server. He is an accomplished SSIS author, teacher at IT Academies and has over 10 years of experience as a QE and developer for SQL Server related software. He has worked for the government, oil companies, web sites, magazines and universities around the world. Daniel also regularly speaks at SQL Servers conferences and blogs. Read more

      Related Posts


      Why Choose Stellar?

      • 0M+


      • 0+

        Years of Excellence

      • 0+

        R&D Engineers

      • 0+


      • 0+


      • 0+

        Awards Received