Manual Solutions to Fix SQL Server Attach Error 5123

Rate this post

Sometimes the user wants to attach a Database file from a different location to the SQL Server, but he fails to do so and encounters SQL Server Error 5123. This error is basically a permission error, therefore don’t feel threatened by it. As everyone knows that MDF files are the primary files of the SQL database and LDF files are the Log files and when they are attached to the server this error is encountered by the user.

Reasons for Error 5123

• If the user detaches the database files using different logins or tries to attach the file using many login I.Ds then the chances of this error are high.
• This error occurs when there is no permission access is granted to run a particular program folder when a process is already running on the server.

In order to resolve this error the user has to change the permission option or should add new permission as an owner of LDF and MDF files.

Manual Solutions for Error 5123

There are some manual solutions which you can try to resolve this error. If you have a sound knowledge about MS SQL then only try the manual methods.

Run as Administrator

  • Make a Right-Click on the MDF file which you want to attach.
    • Go to Properties and then check the Permission of that file.
    • For providing full control during the Login process, Click on Add button and grant Login permission.

In order to attach an LDF file to the server, apply the same steps mentioned above. You can directly use the Run as Administrator rather than granting permission to every file and fix SQL Server Error 5123.

Try SQL Server Management Studio

  • Open SQL Management Studio and Connect to the server using the appropriate credentials or Windows Authentication.
    • Click on Object Explorer and Select the Databases to see the list of existing Databases.
    • Now, make a Right-Click on the Database and Click on Attach option from the dropdown menu.
    • A new window opens and then Click on Add button to add the database which you want to attach.
    • Review the LDF and MDF files and then Click on OK button to finish the whole process.

Finally, you will be able to attach all the Files to the SQL Server database without facing any error.

Use T-SQL Code

The sp_attach_db stored procedure can also help you to attach all the databases into SQL Server. Use the following code:-

Professional SQL Database Repair Tool

The final option you are left with is to try an automated tool which beats all the manual techniques. This tool helps to fix any kind issues related to the MDF files. Maybe the reason for SQL Server error 5123 is the corruption of MDF files or NDF files, therefore, it needs to be fixed as soon as possible. There are some manual techniques as well to repair the MDF file corruption but they are not 100% successful. Every time the user loses his data.

Therefore I would recommend you to use the SQL Database Repair Tool to fix the corruption issues of the MDF files. You’ll not need any technical expertise to run this tool. It is embedded with an automated GUI which can be used by any user.

Features of SQL File Recovery Software

  • Recovers SQL Database Files of any version.
    • Repairs Corrupted MDF and NDF Files.
    • Fix issues in tables, records, rules, triggers, stored procedures, functions of MDF file.
    • Restore all the Database files on the SQL server without losing any data.
    • Allows the user to save recovered data in SQL Server Database SQL Scripts.
    • Self-Explanatory Graphical User Interface.

Steps to Run the Tool

  • Download and Open SQL Database Repair Tool.

Downlaod SQL Database Repair Tool

  • Add SQL Database MDF file into the Tool
    • Select the Recovery Mode either Advanced Mode or Standard Mode, depending upon the severity of corruption.
    • After the completion of the scanning process, all the files will appear in a Tree-Structured Format.
    • Select the Files you want to save and then Click on Save Button.

Now you can easily attach SQL Database to the server without facing any kind of error.


Well, I have told you the various methods to fix SQL Server error 5123. There are some manual methods and one automated method. So it is up to you to decide which method will be the best option to resolve the error. Apart from the solution I have told you the reasons for this error. I would recommend that you should keep your SQL Database files corruption free. I hope this article might help you in fixing the SQL Server issues.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *