Sql-server – not able to attach the .mdf file

sql-server-2008

I have attached x_Data.mdf and x_Log.ldf file successfully with SQL Server, to replace the same file I deleted and tried to attach with new file having same name. But it is throwing below error statement.

Can anybody please shed some light on this?

Msg 5173, Level 16, State 2, Line 1
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.

Best Answer

You should check the real database name + files it consists of by executing dbcc checkprimaryfile on your mdf file

as described here: SQL SERVER – FIX – Error: One or more files do not match the primary file of the database