SQL Server – Cannot Restore Database Due to Stuck Rollback

restoresql server

When I try to restore my database with

RESTORE DATABASE MyDatabase
FROM DISK = '\path\to\my\backup.bak'
WITH REPLACE, RECOVERY

It says

Exclusive access could not be obtained because the database is in use.

After some googling I tried this instead:

ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE MyDatabase
FROM DISK = '\path\to\my\backup.bak'
WITH REPLACE, RECOVERY
GO

However, this seemed to take forever and when I eventually cancelled the command it told me that

Nonqualified transactions are being rolled back. Estimated rollback completion: 0%.

The message repeated multiple times and the progress was always 0%.

I'm not a DBA –sadly my company does not employ any– and I have no clue where to go from here.

Best Answer

If you can restart the SQL Server service, then:

  • Stop the SQL Server service
  • Delete the old data/log files for MyDatabase
  • Start the SQL Server service again
  • At that point, you can delete the (offline) database
  • Do your restore