Friday, May 10, 2013

SQL Server Databases in Recovery Pending state

If you encounter an error database state “Recovery Pending” don’t panic you’re not aloneJThis is because SQL server has encountered improper shutdown or not mounted properly. Possible reason insufficient permission to the DB file folder may prevent the recovery. Follow the steps mentioned below it might help…
 
 
You can see the various state definitions from following link
 
 
 
If you got this error don’t try to delete the database. Following steps may help you to recover.
 
1.      Restart your sql server instance and check the database state. Still if it is not recovered then continue with next step
2.      Wait for some time (5 or 10 mines) probability it will get online, if not it will go to suspended mode.
3.      If it is in suspended state following link will help you to recover
 
4.      If still it continue with pending state run the following command
 
ALTER DATABASE <> SET OFFLINE WITH ROLLBACK IMMEDIATE
Go
ALTER DATABASE <> SET ONLINE WITH ROLLBACK IMMEDIATE
Go
       This command will help you identify the issue
      
       Ex: Sometime you may receive following error
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "Abc.mdf". Operating system error 5: "5(Access is denied.)".
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "Abc_log.ldf". Operating system error 5: "5(Access is denied.)".
Msg 5181, Level 16, State 5, Line 1
Could not restart database "Abc". Reverting to the previous status.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
5.       Try to give proper access rights to the database file folder and restart the SQL Server.
a.       Check if files are in read-only mode or not. 
b.      Check the SQL server service account it is has access to database file folder.