How to Fix SQL Server 2008 R2 Database Error 5123

Summary: Read this blog to learn about the possible reasons leading to SQL Server 2008 R2 Database error 5123. Also, explore the methods to fix the 5123 error by granting full permissions to the database and then attempting to attach it by using SSMS or T-SQL. For a quick solution to resolve the error and regain access to your database, try using Stellar Repair for MS SQL software. The software can help you recover all the objects from corrupted database (MDF/NDF) files of SQL Server version 2019, 2017, 2016, 2014, 2012, 2008 R2, and lower versions.

The ?SQL Server error: 5123, severity 16, state 1? occurs when attaching database in SQL Server 2008 R2 or higher versions. This may happen when the database you?re trying to attach is placed in a different location.

Figure 1 – SQL database error 5123

Reading the complete error message ?CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file?? clearly indicates that it occurs due to a permission issue.

Now let?s discuss in detail the possible reasons leading to SQL Server error 5123.

Reasons Behind Microsoft SQL Server Error 5123

You may receive the error due to any of these reasons:

How to Resolve SQL Server 2008 R2 Database Error 5123?

To resolve this issue, you will need to change or add permissions as the owner of the MDF and LDF files. To do so, follow these steps:

Step 1: Grant Full Permissions on Database Files

Figure 2 – Select Security in SQL Database Properties Window
Figure 3 – Select Full Control Permission

Step 2 ? Attach the SQL Database

Try attaching the database in SQL Server using any of the following methods:

Method 1: Using SQL Server Management Studio (SSMS)

Figure 4 – Connect to SQL Server Instance
Figure 5 – Select Database To Attach in SQL Server
Figure 6: attach database

Method 2 – Using T-SQL

Attach your SQL database using sp_attach_db stored procedure (deprecated):

sp_attach_db[@dbname=] ?dbname?,[@filename1=] ?filename_n? [ ,?16 ][@dbname=] ? Refers to the name of the database to be attached to the   server.[@filename1=] ? ?filename_n? Is the physical name, including path, of a database file//SAMPLE:EXEC sp_attach_db@dbname = N?MyDatabase?,@filename1 = N?D:\DataFiles\MyDatabase_Data.mdf?,@filename2 = N?E:\LogFiles\MyDatabase_Log.ldf?;

Note: Update correct path values in the above command as per your system settings.

After executing the above steps, you won?t experience any issue when trying to attach database failed for SQL Server 2008 R2. You can see the attached databases in SQL instance.

What if the Error Persists?

If the above solution failed to fix the error, that might be an indication that there is a problem within your SQL database. In such a case, you?ll need to repair the SQL database to overcome the error try Stellar Repair for MS SQL. This SQL recovery software is purpose-built to fix all types of corruption errors of SQL Server database. It also helps recover inaccessible objects from MDF and NDF database files. The software repairs a database file while preserving its integrity.

End Note

Though SQL database repair software should succeed in resolving the error, in the rare event if it fails, contact Microsoft customer support for professional assistance.

Related Post