Database Keeps Going into Recovery Pending State
11:39 11 Sep 2019

I have a SQL server database that has been running perfectly fine on my machine for about 6 months, a couple days ago out of nowhere it was inaccessible (Pending Recovery).

I did a bunch of Googling and have tried the following things to fix the issue but thus far restoring it from a previous backup is the only thing that seems to work.

I have tried (From SMS and SQLCMD):

  1. ALTER DATABASE mydatabase SET EMERGENCY
  2. ALTER DATABASE mydatabase set single_user
  3. DBCC CHECKDB (mydatabase, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
  4. ALTER DATABASE mydatabase set multi_user

Step #3 errors out with: "cannot open mydatabase is already open and can only have one user at a time"

Second try:

  1. EXEC sp_resetstatus 'mydatabase';
  2. ALTER DATABASE mydatabase SET EMERGENCY
  3. DBCC CHECKDB ('mydatabase')
  4. ALTER DATABASE mydatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
  5. DBCC CHECKDB ('mydatabase', REPAIR_ALLOW_DATA_LOSS)
  6. ALTER DATABASE mydatabase SET MULTI_USER

Step #5 errors out with the same error.

My question is what could be causing this in the first place and how can I fix it properly without having to do a restore twice a day.

sql-server t-sql sql-server-2012