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.
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.
You may receive the error due to any of these reasons:
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:
Figure 2 – Select Security in SQL Database Properties Window
Figure 3 – Select Full Control Permission
Try attaching the database in SQL Server using any of the following methods:
Figure 4 – Connect to SQL Server Instance
Figure 5 – Select Database To Attach in SQL Server
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.
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.
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.
Samuel Okudjeto is a technology enthusiast with great interest in database administration and analytics. He has many certifications including the Microsoft Certified Expert Professional. Along with 6+ years of hands-on experience, he holds a Masters of Science degree in Business Analytics. Read more
Stellar Repair for MS SQL is an enterpriRead More
3-in-1 software package, recommended byRead More
Stellar Converter for Database is an effRead More
Powerful tool, widely trusted by users &Read More