This is a very common error which may occur during migration of SQL Database files. The reason may be due to the corruption of files or due to different file names. Therefore the user encounters error 5173 cannot associate files with different databases. In this article, I am going to discuss how to resolve this error manually.
Explanation of Error 5173
In a layman term, this error occurs when the user tries to open the SQL database and due to corruption or missing content the file doesn’t open. This is an attach error where the user has moved from one database to another but after migration, he is not able to access the file.
There is a lot more to tell about this error but we can discuss it later. First of all, let’s see how we can resolve this error.
Types of Files on the SQL Server
- MDF Files– This is a primary data file with an extension and all the other details.
- NDF Files– This is a secondary data file which is not created by default. When the user wants to separate the data into different hard drives for security reasons then this file is created.
- LDF Files– This file contains the log information. It helps in recovering the data from the database.
You can use the sp_helpfile system to view all the files present on the database. It will show you the file size, location, and ID.
You May Also Read- Fix SQL Server Error 945.
Fix Cannot Associate Files with Different Databases Error
The primary data file doesn’t match the log file and therefore the user faces such errors. It can be fixed:-
- Inspect whether the primary data file matches the log file or not. Sometimes the user attaches the wrong log file with the Primary file.
- If the primary data is missing then you have to use the SQL Repair Tool to fix the corruption and resolve the error 5173.
You can Download the Software form below:-
The MS SQL Database Recovery software helps the user to repair the MDF file and then the user will not face such errors. It also supports BLOB, Images, XML and large page data. This tool is compatible with all the versions of windows.
If you are having some problem with the LDF file then you can recreate it.
Recreate LOG File
If you are unable to find the correct LDF file then you can rebuild it for the MDF file that you have recently recovered. Enter the following SQL code to Rebuild the File.
CREATE DATABASE yourdatabase
ON (FILENAME = ‘c:\yourPrimaryFile_Data.mdf’)
FOR ATTACH_REBUILD_LOG ;
A new database would be created on the MDF file. By this attach_rebuild_log code, you can create a new log file for the MDF files.
So the error 5173 cannot associate files with different databases occurs when there is a problem in the MDF file and in the Log file. Due to some negligence, the two files don’t match each other and the system interprets it as the files of two different databases.
But if the primary file is corrupted then you can repair it by using the third party software. Once you repaired it then you can match both the file by creating a new Log file using attach_build_log. Hope you liked this article.