Take the 2-minute tour ×
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. It's 100% free, no registration required.

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 stackoverflow.com 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

1 Answer 1

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 mindsdoor.net/SQLAdmin/RecoverCorruptDatabase.html 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

 
discard

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.