7

I have created a database in SQL Server 2012 with mdf and ldf pointing to a external hard drive attached to my machine. I created tables, stored procedures, populated tables, etc. etc. I removed the hard drive at the end of the day.

Today, when I attached the hard drive and tried to access the DB in Management Studio, I see the name of the database with (Recovery Pending).

What does this mean? I see the mdf and ldf files in the D drive.

blue piranha
  • 3,706
  • 13
  • 57
  • 98

5 Answers5

12

What worked for me was to take the database offline*, then back online - no RESTORE DATABASE was necessary in this case, so far as I can tell.

In SQL Server Management Studio:

  1. right-click on the database
  2. select Tasks / Take Offline ... breathe deeply, cross fingers...
  3. right-click on the database again
  4. select Tasks / Take Online
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • Perfect!! Although, for me, I had to close and reopen SSMS afterwords to get the database objects to repopulate. – Jim Simson Nov 11 '18 at 14:00
9

When you removed the drive, you forcefully disconnected the database from the SQL Server service. SQL Server does not like that.

SQL Server is designed by default so that any database created is automatically kept open until either the computer shuts down, or the SQL Server service is stopped. Prior to removing the drive, you should have "Detached" the database, or stopped the SQL Server service.

You "may" be able to get the database running by executing the following command in a query window: RESTORE DATABASE [xxx] WITH RECOVERY;

You could, although I would not normally recommend this, alter the database to automatically close after there are no active connections.

To accomplish this, you would execute the following query:

ALTER DATABASE [xxx] SET AUTO_CLOSE ON WITH NO_WAIT;
Hannah Vernon
  • 3,367
  • 1
  • 26
  • 48
2

Another way that works is to "Restart" the Database Engine. If feasible and/or practical for this server, it may be faster whenever you have several DB in the external drive.

In SQL Server Management Studio:

  1. Attach the external drive
  2. right-click on the database engine : Server Name(SQL Server 12.0.2000 ... etc)
  3. Select "Restart"
  4. Answer Yes when asked if you want to proceed
Ignacio
  • 64
  • 1
  • 3
1

Below worked for me:

  1. Run SQL Management Studio as Administrator (right click on SQL Management Studio icon and select 'Run As')
  2. Take database offline
  3. Detach the database using DROP option
  4. Attach the database
  5. If you were using this database with a Web App running on IIS then you may need to restart the IIS Server

Hope this helps someone

Anima-t3d
  • 3,431
  • 6
  • 38
  • 56
Ainsof
  • 124
  • 1
  • 1
0

If the SQL Server knows that database recovery needs to be run but something is preventing it from starting, the Server marks the db in ‘Recovery Pending’ state. This is different from the SUSPECT state because it cannot be said that recovery is going to fail – it just hasn’t started yet.

Check this thread: How to fix Recovery Pending State in SQL Server Database?

Priyanka
  • 21
  • 1