Earlier today I was experiencing an issue with one of our databases called SALES_DB is in Restoring state. I tried to run below ALTER DATABASE commands on the database to set it in online state but it throws the following error.
ALTER DATABASE SALES_DB SET OFFLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE SALES_DB SET ONLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE is not permitted while a database is in the Restoring state.
The database seems to be stuck in RECOVERING state forever. Somehow database restore operation has hung or fails to complete, leaving the database inaccessible in a restoring state, usually this is because the database log is missing or corrupt.
1. First check .mdf and .ldf files are exist.
2. Check data and log drives are online and available.
3. Try to stopping and restarting the SQL service.
4. If nothing works you can use below code to recover your database;
RESTORE DATABASE SALES_DB WITH RECOVERY;
As soon as successfully restored the database take full backup.