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.
Recovery Pending: When the SQL server knows that the database needs to be restored but there is an obstacle before starting. This status differs from the suspect mode because it cannot be declared that the database restore has failed but the process has not yet started.
Right-Click on the Database and Delete it to remove SQL recovery pending state permanently.
Method 1 – Run DBCC CHECKDB Command with REPAIR Option You can try to bring the database back online by setting it to EMERGENCY mode. Doing so, will mark the database read-only. Once the database is accessible, run the DBCC CHECKDB command with 'REPAIR_ALLOW_DATA_LOSS' option.
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:
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With