I have a c# application that is connected to my sql server 2005 database, i am working on the application to insert some entries in the database and due to power failure system got down and from that time onwards i am getting this error. I refresh the database, make a copy of it, delete it & try to attach it again and thus the error occurs.

The log cannot be rebuilt because there were open transactions/users when the database 
was shutdown, no checkpoint occurred to the database, or the database was read-only. This  error could occur if the transaction log file was manually deleted or lost due to a hardware  or environment failure.

If i use the log file while attaching the db, i got this error

The log scan number (1224:41:1) passed to log scan in database 'test' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.

Kindly help Thanks

  • What happened to the transaction log (ldf file?) Dec 27, 2011 at 17:04

1 Answer 1


Try attaching the databse with ATTACH_REBUILD_LOG after moving the original log file.

  • I got the same error when i try to do it with Attach_rebuild_log
    – MegaMind
    Dec 27, 2011 at 17:12
  • Bad luck my friend, i can't remember exactly if dbcc check would be helpful in these situations Dec 27, 2011 at 17:14
  • Take a look at this mindsdoor.net/SQLAdmin/RecoverCorruptDatabase.html and also look for sql server repair tools in case of unsuccessful try. Dec 27, 2011 at 17:25
  • Thanks, that is a great article, but your second advice do the work for me, SQL Repair tools restore the database,
    – MegaMind
    Dec 27, 2011 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.