In SQL Server 2012 I am trying to attach a .mdf file to a database. The thing is there were still open transactions when my server was shut down. Then I reinstall the server and I have deleted the .ldf file.
Now when I try to attach the .mdf file in SSMS, an error says without .ldf file a .mdf file cannot be attached because there was open transaction.
Does anyone know a solution?
Many thanks!
Best Answer
Ypu can use hack attach method described by Paul Randal here: hack-attach a damaged database
In your case you should delete both mdf and ldf files of newly created database and copy only your mdf to the file location.
Your database will be attached but cannot run recovery, so it will be marked as
SUSPECT
Then you can try to put it intoEMERGECY
mode and extract as much data as possible.Seee here an example: Using EMERGENCY mode to access a RECOVERY PENDING or SUSPECT database