Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Dec 28 '11 at 12:24

This question came from our site for professional and enthusiast programmers.

What happened to the transaction log (ldf file?) – Martin Smith Dec 27 '11 at 17:04
up vote 2 down vote accepted

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

share|improve this answer
I got the same error when i try to do it with Attach_rebuild_log – MegaMind Dec 27 '11 at 17:12
Bad luck my friend, i can't remember exactly if dbcc check would be helpful in these situations – Jani Dec 27 '11 at 17:14
Take a look at this and also look for sql server repair tools in case of unsuccessful try. – Jani Dec 27 '11 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 '11 at 18:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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