Click here to Skip to main content
6,822,613 members and growing! (20,492 online)
Email Password   helpLost your password?
Database » SQL Reporting Services » General     Advanced License: The Code Project Open License (CPOL)

How to Restore SQL Server 2005 Suspect Database

By Suvendu Banik

How to Restore SQL Server 2005 Suspect Database
SQL, Windows, Visual-Studio, SQL2005, DBA, Dev
Revision:2 (See All)
Posted:4 Sep 2007
Updated:13 Sep 2007
Views:75,660
Bookmarked:31 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
28 votes for this article.
Popularity: 5.40 Rating: 3.73 out of 5
5 votes, 17.9%
1

2

3
4 votes, 14.3%
4
19 votes, 67.9%
5

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


Member
Love to code
Occupation: Program Manager
Location: India India

Other popular SQL Reporting Services articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 31 (Total in Forum: 31) (Refresh)FirstPrevNext
GeneralThis worked like a charm. PinmemberMember 425932110:35 5 Dec '09  
Generalbacking up a database in spsupect status PinmemberLido Taha23:47 14 Oct '09  
Generalit restores the database but there is loss of data PLEASE HELP Pinmembertheodoraaaa6:11 28 Sep '09  
GeneralIt worked for me Pinmembermercyjms1:29 24 Sep '09  
GeneralThank you so much. Good work !!! Pinmembertomket_669:43 6 Sep '09  
GeneralThanks man it worked Pinmemberashishshevale0:46 31 Aug '09  
QuestionThis doesn't work on system databases Pinmembersrulyt2:55 22 Jun '09  
AnswerThanks to author Pinmemberchatakan0:44 7 Jul '09  
GeneralSaved me too. PinmemberShai Bar-Lev23:15 29 Apr '09  
GeneralWorked for me. Pinmemberteza5915:08 18 Feb '09  
GeneralTHANKS!!!! Pinmemberadmlange0:16 18 Feb '09  
GeneralThank-you very much! PinmemberMarkCorsi6:38 9 Jan '09  
GeneralThanks, I owe you one big time! Pinmembersrulyt23:50 16 Nov '08  
QuestionDatabase Suspect Error Pinmembersujithkumarsl0:00 10 Nov '08  
GeneralThank you!!! PinmemberLuis C. Lopez8:50 3 Nov '08  
GeneralYou are a god amongst children PinmemberKosher16:16 18 Sep '08  
GeneralFixed my problem PinmembereNocNRoll9:01 17 Jun '08  
GeneralRe: Fixed my problem PinmemberSuvendu Banik0:58 23 Jun '08  
GeneralAnother success story! PinmemberKent Rothrock7:43 15 Jun '08  
Generalrestore suspect database in SQL-2000 Pinmembersqlbie7:38 2 Jun '08  
GeneralRe: restore suspect database in SQL-2000 PinmemberSuvendu Banik18:53 2 Jun '08  
GeneralIt worked for me. PinmemberKenThompson5:16 20 May '08  
GeneralRe: It worked for me. PinmemberSuvendu Banik18:55 2 Jun '08  
GeneralWhy? Pinmemberdragoshilbert22:18 17 Sep '07  
GeneralRe: Why? PinmemberMember 353052520:17 12 Apr '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 13 Sep 2007
Editor: Deeksha Shenoy
Copyright 2007 by Suvendu Banik
Everything else Copyright © CodeProject, 1999-2010
Web11 | Advertise on the Code Project