17 June 2011

Fixing Sharepoint’s “Cannot connect to the configuration database” error

I have Sharepoint Server 2010 installed in my development environment. It happened a couple of times that the computer hangs and the Sharepoint Configuration dabatase remains in a corrupted state. When I try to access the Sharepoint local site from the browser it gives the following error:

Cannot connect to the configuration database.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot connect to the configuration database.

So, how did I fix it?

I first used this addselftosqlsysadmin.cmd script to add my account to the SQLServer sysadmin group.

Then performed the following commands from SQL Server Management Studio:

select state_desc from master.sys.databases where name = 'SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45'

The result was: SUSPECT, confirming we had a problem.

Then run:

ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]  SET EMERGENCY;

GO

ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]  SET SINGLE_USER;

GO

DBCC CHECKDB ([SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45] , REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;

GO

ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]  SET MULTI_USER;

GO

That’s it! I run the state_desc command again and this time it says: ONLINE

Solved!

No comments: