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.

We had several power outages and server rebooted couple times which seemed to cause issues with one of the databases. We tried detaching at attaching database again but it looks like database is corrupted and we’re getting the

Msg 5172, Level 16, State 15, Line 1

Claiming that database header is invalid. Is there anything we can to do repair database or extract data from MDF file? We do have a backup but it’s like 2 weeks old and doesn’t contain all data.

share|improve this question

migrated from stackoverflow.com Apr 5 '13 at 20:00

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

    
Do you have a readable log file? If so you might be able to restore the 2 week old backup and use the transaction log for the rest of the data. What was your recovery model set to for the database? –  SQL Heroes Apr 5 '13 at 9:17

1 Answer 1

up vote 2 down vote accepted

I’d try the procedure described below or third party tool such as ApexSQL Recover if that doesn’t work and database is severely corrupted.

There might be other options out there. This is something that worked for me once but there are no guarantees that it will work at all times.

Stop SQL Server instance -> Copy MDF and LDF files to another location -> Delete original MDF and LDF files -> Start SQL Server instance again -> Create new database with exact same name and file names -> Stop SQL Server -> overwrite newly created MDF and LDF.

After this your database should be back online. If it is then go ahead and put it into EMERGANCY mode and SINGLE USER mode.

Finally go ahead and execute DBCC CHECKDB like this

DBCC CHECKDB (databaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS

If you can get to this and execute last command successfully you should be good. If not then your only options are restoring from backup and/or using 3rd party tools.

share|improve this answer
1  
This is a good approach if you keep the original backup's safe, BUT be carefull: REPAIR_ALLOW_DATA_LOSS means that some data might be lost in the DB even if it attached successfully. Further to your Restore solution, how up to date is your transaction log and when was the last entry? You might be able to restore your 2 week old backup and replay the transaction log for the rest of the data. Before you start anything, keep all ldf and mdf and ndf file originals in a safe place and work only on copies. –  SQL Heroes Apr 5 '13 at 9:14

protected by Mark Storey-Smith Sep 20 '13 at 13:07

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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