lørdag den 29. oktober 2011

We all live in a suspect DB world

I have Reporting Services 2008 R2 developer edition installed on my laptop.
As I tried to connect this morning to my reporting services url : http://w30141:8080/ReportServer_W30141 , I received the following error message :

Reporting Services Error

The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing. (rsReportServerDatabaseUnavailable) Get Online Help
Cannot open database "ReportServer$W30141" requested by the login. The login failed. Login failed for user 'NTXXXX\YYYYYY'.  ( I won't disclose my domain login account even on my blog)


I checked the service and it was up and running but the reporting service database ReportServer$W30141 was in suspect mode. You can not access a database in suspect mode and the option of making a backup or restore of this database was disabled as well. So how can we handle this situation ?

We all remember that SQL Server 2005 introduced a new DB Status called Emergency. This mode can change the DB from Suspect to Emergency mode, so that you can retrieve the data in read only mode.
Emergency repair mode it's a one-way operation. Anything it does cannot be rolled back or undone.
As it's a one-way operation, you cannot wrap it in an explicit user-transaction.
You may use the option REPAIR_ALLOW_DATA_LOSS to ensure the database is returned to a structurally and transitionally consistent state and this is actually the only repair option available in emergency mode.  You may be tempted to use REPAIR_REBUILD, but it won't work.
So I used the following script :

EXEC sp_resetstatus 'ReportServer$W30141'
ALTER DATABASE ReportServer$W30141 SET EMERGENCY
DBCC checkdb('ReportServer$W30141')
ALTER DATABASE ReportServer$W30141 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('ReportServer$W30141', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE ReportServer$W30141 SET MULTI_USER

I did not find any data loss as far as I could see, as I could access and run all my reports hosted in this database.

So if you encounter in the future a database in suspect mode, use the above script. It worked for me once again for the AdventureWorks 2008 database. 

Ingen kommentarer:

Send en kommentar