-
Written By Gaurang Sharad
-
Updated on August 24th, 2022
If you are a SQL Server user then there is a big chance that you have encountered SQL Server 2008 R2 Database error 5123 during its execution. Whenever a user tries to create a new database file from a remote location S/He face this error code. It’s a permission error so there is no need to worry about and you can fix it very easily.
There are two files used by SQL database, one is MDF and another is LDF. Where MDF is the primary file which contains schema and data, on the other hand, LDF stores logs. Whenever a user tries to attach these files to the server, the error takes place. So in this article, you will go through all the reasons and ways to fix this blunder in SQL server 2008 R2 Database.
Whenever the error takes place the user gets a dialog box like this, notifying about the issue:
In such a situation the best way is to change the permission option or should try to create a new permission option as a new owner of MDF and LDF file.
You Might Like:
Fatal Error 823 in MS SQL Server Database
Fix MySQL Error 1146 Table doesn’t exist
There are multiple manual solutions available to fix this error. To resolve this issue, you can use any of the methods:
Same goes with the LDF file, to attach it on the server, follow the above method. You can directly Run As Administrator rather granting permissions to each file. By doing so, you can easily fix SQL error 5123 in Server 2008 R2 database.
Using a stored procedure, we can attach a database in the SQL server. Below is a syntax to attach a database:
sp_attach_single_file_db [@db_name=] ‘db_name’, [@physname=] ‘physical_name
[@db_name =] ‘db_name’ is the database name. ‘db_name’ is nvarchar (128).
[@physname =] ‘phsyical_name’ is the database file name. ‘phsyical_name’ is nvarchar (260).
Example:
EXEC sp_attach_db @name = ‘employer’
@filename1 = ‘C:\MSSQL\Data\employer.mdf
@filename2 = ‘C:\MSSQL\Data\employer_log.ldf
By following the above method, you can attach the database file to the SQL server and can easily fix Error 5123.
SQL Repair is a utility which lets you review the whole database transactions and then it saves all the transaction as a new database file or as a SQL script. It takes MDF file as input and generates the preview of the SQL database. Later you can export the queries like INSERT, UPDATE and DELETE in a new database or script with all the constraints. It exports the newly created database automatically. Windows authentication can be used to login to the server or you can manually provide the user login credentials. Then all the work is done by the utility itself. To use this utility, follow the below steps:
By following the above process, you will end up creating a new database same as the old one and then the utility will automatically attach the database to the SQL server. This way you can fix SQL error 5123 in server 2008 R2. You can directly download the tool from the above link and can easily fix the issue.
About The Author:
Related Post
© Copyrights 2018-2023 ConverterTools All rights reserved.