I backed up a database:
BACKUP DATABASE MyDatabase
TO DISK = \'MyDatabase.bak\'
WITH INIT --overwrite existing
And then tried to restore it
All the WITH RECOVERY based options did not work for me.
What did was to do the complete restore from Management Studio.
USE [master]
RESTORE DATABASE Sales_SSD
FROM DISK = N'D:\databaseBackups02\Daily_Sales_20150309_0941.bak'
WITH FILE = 1,
MOVE N'Sales_Data' TO N'C:\Data\SSD\Sales.mdf',
MOVE N'Sales_Log' TO N'C:\Data\SSD\Sales_1.ldf',
NOUNLOAD, REPLACE, STATS = 5
Use the following command to solve this issue
RESTORE DATABASE [DatabaseName] WITH RECOVERY
What fixed it for me was
I had a similar incident with stopping a log shipping secondary server. After the command to remove the server from log shipping and stopped the log shipping from primary server the database on secondary server got stuck in restoring status after the command
RESTORE DATABASE <database name> WITH RECOVERY
The database messages:
RESTORE DATABASE successfully processed 0 pages in 18.530 seconds (0.000 MB/sec).
The database was usable again after those 18 seconds.
I had a . in my database name, and the query didn't work because of that (saying Incorrect syntax near '.') Then I realized that I need a bracket for the name:
RESTORE DATABASE [My.DB.Name] WITH RECOVERY
I had a similar issue with restoring using SQL Management Studio. I tried to restore a backup of the database to a new one with a different name. At first this failed and after fixing the new database's file names it was successfully performed - in any case the issue I'm describing re-occurred even if I got this right from the first time. So, after the restoration, the original database remained with a (Restoring...) next to its name. Considering the answers of the forum above (Bhusan's) I tried running in the query editor on the side the following:
RESTORE DATABASE "[NAME_OF_DATABASE_STUCK_IN_RESTORING_STATE]"
which fixed the issue. I was having trouble at first because of the database name which contained special characters. I resolved this by adding double quotes around - single quotes wouldn't work giving an "Incorrect syntax near ..." error.
This was the minimal solution I've tried to resolve this issue (stuck database in restoring state) and I hope it can be applied to more cases.