Issue:

Unable to load my SharePoint site hosted on a VM. Page threw the error viz. ‘Cannot connect to configuration database’

Resolution (Steps taken):

  1. Observed that ‘SharePoint_Config’ DB was in Suspect mode. In SSMS, I found the Suspect status with SharePoint_Config DB
  2. On restarting SQL services, Recovery status was displayed with SharePoint_Config DB
  3. After the recovery process completed, the DB name was rendered properly in SSMS; but, page still threw the error viz. ‘Cannot connect to configuration database’
  4. After some time, Suspect status had resurfaced on viewing in SSMS. This showed that the DB was still corrupt
  5. In such scenarios, one option would have been to restore the DB with an old backup. In my case, I did not have a backup L
  6. On searching the net, I found few blogs mentioning this issue
    1. http://nikspatel.wordpress.com/2011/03/02/sharepoint_config-suspect-mode-cannot-connect-to-the-configuration-database-error/
    2. http://ahmershahid.wordpress.com/2009/05/25/moss-2007-config-db-in-suspect-mode/
  7. As per the blogs, the SharePoint DB gets corrupt occasionally when the VM restarts untowardly
  8. Script that helped me resolve the issue:
    -- Use the Master database
    Use Master
    
    -- Verify that database has issues
    EXEC sp_resetstatus 'SharePoint_Config'
    
    -- Put the database in emergency mode
    ALTER DATABASE SharePoint_Config SET EMERGENCY
    DBCC checkdb('SharePoint_Config')
    
    -- Set the database in single user mode
    ALTER DATABASE SharePoint_Config SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    
    -- Repair the database with data loss
    DBCC CheckDB ('SharePoint_Config', REPAIR_ALLOW_DATA_LOSS)
    
    -- Set the database in multi-user mode
    ALTER DATABASE SharePoint_Config SET MULTI_USER
    
    -- Verify that database is reset
    EXEC sp_resetstatus 'SharePoint_Config'
    
    
  9. PFA: SharePoint_Config_Recovery.sql, SQL script mentioned in the blogs which helped me resolve the issue
  10. Script tries to set the DB in Emergency mode and repair the data loss. This should be applicable to any DB which gets corrupt and goes into Suspect mode