Click here to Skip to main content
Click here to Skip to main content

How to Restore SQL Server 2005 Suspect Database

By , 13 Sep 2007
 

Introduction

If your project's database is in suspect mode, then no transaction will take place until and unless you repair your database. That causes a show stopper for your up and running application. Here, you will find a way to get out of this.

Background

Your Database is in Suspect Mode. I guess, you haven't experienced this problem till now. But, if it comes to you and if the database is LIVE, then it's time to read this article to get out of this tension.

Using the Code

If you find your database in Suspect mode, then please keep your nerve strong. Just proceed step by step what I am written below. I think you will get out of this trouble. SQL Server 2005 introduced a new DB Status called Emergency. This mode can change the DB from Suspect mode to Emergency mode, so that you can retrieve the data in read only mode. The steps are... After executing the script given below, you will get back your database in operational mode. Actually I have tried with two of my existing live systems and found no data loss.

Note: Obviously there are two more options available. Run REPAIR_ALLOW_DATA_LOSS to ensure the database is returned to a structurally and transitionally consistent state. Here are a few things to bear in mind about emergency mode repair: it's a one-way operation. Anything it does cannot be rolled back or undone. If this worries you (if someone ever got into that state, then surely don't have the healthy concern about data that they should have in the first place) then make a copy of the damaged database before you run emergency mode repair.
As it's a one-way operation, you cannot wrap it in an explicit user-transaction.
It's the only repair option available in emergency mode - if you try to use REPAIR_REBUILD, then it won't work.

EXEC sp_resetstatus 'yourDBname';
ALTER DATABASE yourDBname SET EMERGENCY
DBCC checkdb('yourDBname')
ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE yourDBname SET MULTI_USER

Points of Interest

You will be happy that your database as well as the application are still in workable condition. :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Suvendu Banik
Program Manager
India India
Member
Love to code

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionThank YoumemberMember 855142811 Apr '13 - 21:58 
QuestionThanksmemberDell.Simmons9 Apr '13 - 11:26 
GeneralThanksmemberCode4Tech5 Dec '12 - 1:11 
Questionhow to secure database in client system in desktop applicationmemberMember 362275216 Nov '12 - 3:05 
Question5 Stars here too!memberbortolo5 Oct '12 - 11:53 
QuestionVery good!memberGilberto Campos25 Sep '12 - 12:36 
GeneralMy vote of 5memberCraig Errington20 Sep '12 - 5:45 
Questionit really works..memberakshar shroff7 Jun '12 - 21:15 
GeneralMy vote of 5memberashutosh300731 May '12 - 22:23 
GeneralMy vote 5 starsmemberNorbert Meier17 Apr '12 - 23:23 
GeneralMy vote of 5memberMember 868252827 Feb '12 - 13:36 
GeneralMy vote of 5membernawazish12khan2 Dec '11 - 22:24 
GeneralMy vote of 5memberasrij8 Nov '11 - 17:48 
AnswerPerfect solution. my vote is 10 of 5membermkwiatkowski8120 Oct '11 - 13:32 
GeneralMy vote of 5memberMember 420927822 Sep '11 - 1:35 
GeneralMy vote of 4memberakhil khare15 Sep '11 - 21:39 
QuestionThank you very much from Paris! It works for me !memberCybertipunch12 Jul '11 - 3:10 
GeneralI can't even begin to thank you enoughmemberBRM_Archer29 Jun '11 - 11:16 
GeneralMy vote of 5memberTheChange1 Jun '11 - 23:19 
GeneralThanks!!!memberLuis Alonso Ramos13 Apr '11 - 14:04 
GeneralMy vote of 5memberthirinwe30 Mar '11 - 19:00 
Generalits workingmemberyvarjun21 Nov '10 - 20:20 
GeneralThanks this workrd for mememberVuyiswa Maseko24 Mar '10 - 22:24 
GeneralThis worked like a charm.memberMember 42593215 Dec '09 - 9:35 
Generalbacking up a database in spsupect statusmemberLido Taha14 Oct '09 - 22:47 
Generalit restores the database but there is loss of data PLEASE HELPmembertheodoraaaa28 Sep '09 - 5:11 
GeneralIt worked for memembermercyjms24 Sep '09 - 0:29 
GeneralThank you so much. Good work !!!membertomket_666 Sep '09 - 8:43 
GeneralThanks man it workedmemberashishshevale30 Aug '09 - 23:46 
QuestionThis doesn't work on system databasesmembersrulyt22 Jun '09 - 1:55 
AnswerThanks to authormemberchatakan6 Jul '09 - 23:44 
GeneralSaved me too.memberShai Bar-Lev29 Apr '09 - 22:15 
GeneralWorked for me.memberteza5918 Feb '09 - 14:08 
GeneralTHANKS!!!!memberadmlange17 Feb '09 - 23:16 
GeneralThank-you very much!memberMarkCorsi9 Jan '09 - 5:38 
GeneralThanks, I owe you one big time!membersrulyt16 Nov '08 - 22:50 
QuestionDatabase Suspect Errormembersujithkumarsl9 Nov '08 - 23:00 
GeneralThank you!!!memberLuis C. Lopez3 Nov '08 - 7:50 
GeneralYou are a god amongst childrenmemberKosher18 Sep '08 - 15:16 
GeneralFixed my problemmembereNocNRoll17 Jun '08 - 8:01 
GeneralRe: Fixed my problemmemberSuvendu Banik22 Jun '08 - 23:58 
GeneralAnother success story!memberKent Rothrock15 Jun '08 - 6:43 
Generalrestore suspect database in SQL-2000membersqlbie2 Jun '08 - 6:38 
GeneralRe: restore suspect database in SQL-2000memberSuvendu Banik2 Jun '08 - 17:53 
GeneralIt worked for me.memberKenThompson20 May '08 - 4:16 
GeneralRe: It worked for me.memberSuvendu Banik2 Jun '08 - 17:55 
GeneralRe: It worked for me.memberJoginipalli Vamshi Krishna13 Jun '11 - 21:11 
QuestionWhy?memberdragoshilbert17 Sep '07 - 21:18 
AnswerRe: Why?memberMember 353052512 Apr '08 - 19:17 
GeneralREPAIR_ALLOW_DATA_LOSS optionmemberchopeen13 Sep '07 - 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by Suvendu Banik
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid