SQL Server Log File Does Not Match the Primary File

Resolved SQL
CM
Community Member
July 01, 2015
3 replies
1,718 views
Reviewed by moderators

Hi, rnI have a question regarding the error "log file does not match primary file". last month, in SQL Server 2008 r2 databases was moved to a 2012 server. One of two moved it by either restored. bak or copied. mdf &. ldf & attached, but I choose second one. This past Sunday the server rebooted at 6:18am, not a planned reboot, immediately after the database became "inaccessible" and the error "log file does not match primary file" was in the log.

Please help me to out of this

3 Answers
Accepted Answer
Verified by Edwin J. Hoffer, Expert · Reviewed July 2015

Please posts your errors message from the SQL Server Error Log to analyze your error in more sophisticated way. n

Hi nThe below Error MSGs I gotnnError: 5173, which shows "One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from a backup"nnError: 17207, Severity: 16, State: 1. nFileMgr: StartLogFiles: Operating system error 2(The system cannot find the file specified.) occurred while creating or opening file 'x:\xxxx\LOGS\xxxx_log. ldf'. Diagnose and correct the operating system error, and retry the operation. nnPlease Help Me

1. Create a new database with same name to default database location. n2. Stop SQL server. n3. Copy old mdf file to overwrite newly created mdf file and delete new ldf filen4. Start SQL Server, database will be in emergency moden5. Detach the emergency mode databasen6. Copy original ldf file to default database location (where new LDF file as created and deleted under step 3 above. n7. Attach the database MDF file. nnHope it will work for you