Skip to content

Instantly share code, notes, and snippets.

@sumuongit
Last active November 19, 2020 08:12
Show Gist options
  • Save sumuongit/cfe4ab11ce3e557a0245906a76328e85 to your computer and use it in GitHub Desktop.
Save sumuongit/cfe4ab11ce3e557a0245906a76328e85 to your computer and use it in GitHub Desktop.
A way to fix recovery pending state in SQL Server database

Execute these queries to fix SQL server database in recovery pending state:

ALTER DATABASE [DBName] SET EMERGENCY
GO
ALTER DATABASE [DBName] SET single_user
GO
DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS
GO
ALTER DATABASE [DBName] SET multi_user
GO

EMERGENCY mode marks the SQL Server database as READ_ONLY, deactivates logging, and gives the permission to system admin only. This method is capable of resolving any technical issue and bringing the database back to the accessible state. The database will automatically come out of the EMERGENCY mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment