650

I backed up a database:

BACKUP DATABASE MyDatabase
TO DISK = 'MyDatabase.bak'
WITH INIT --overwrite existing

And then tried to restore it:

RESTORE DATABASE MyDatabase
   FROM DISK = 'MyDatabase.bak'
   WITH REPLACE --force restore over specified database

And now the database is stuck in the restoring state.

Some people have theorized that it's because there was no log file in the backup, and it needed to be rolled forward using:

RESTORE DATABASE MyDatabase
WITH RECOVERY 

Except that, of course, fails:

Msg 4333, Level 16, State 1, Line 1
The database cannot be recovered because the log was not restored.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

And exactly what you want in a catastrophic situation is a restore that won't work.


The backup contains both a data and log file:

RESTORE FILELISTONLY 
FROM DISK = 'MyDatabase.bak'

Logical Name    PhysicalName
=============   ===============
MyDatabase    C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase.mdf
MyDatabase_log  C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase_log.LDF
Ed Schwehm
  • 2,163
  • 4
  • 32
  • 55
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 6
    I had the exact same issue and all of the solutions failed. Interestingly, I logged onto the SQL server directly and issued the `DROP DATABASE db` command through SSMS and it worked (earlier I was using SSMS from another machine to issue the commands). I am guessing the other solutions would have worked as well. – Salman A Apr 27 '17 at 12:44

29 Answers29

890

I had this situation restoring a database to an SQL Server 2005 Standard Edition instance using Symantec Backup Exec 11d. After the restore job completed the database remained in a "Restoring" state. I had no disk space issues-- the database simply didn't come out of the "Restoring" state.

I ran the following query against the SQL Server instance and found that the database immediately became usable:

RESTORE DATABASE <database name> WITH RECOVERY
Evan Anderson
  • 14,051
  • 3
  • 21
  • 14
  • 6
    We had a DB stuck in restore for 2 hours. We ran this command from a different machine against master and it fixed us right up. Thanks! – Pete Jun 14 '11 at 18:08
  • 19
    +1, with a gotcha. When I ran this, I got an error message saying that the database was already fully recovered. But it still showed as being "In Recovery" state. So I right-clicked it in Management Studio, hit Refresh and it was back to normal. – dario_ramos Sep 03 '12 at 17:22
  • 3
    I restored using the Mng Studio wizard, entered a new database name but by mistake left the filenames as the same as an existing database. I got the error "restore failed but log tail successful" and database attached to those files was stuck in a restoring state. This command appears to have restored the database to its prior state. – Chris Apr 24 '14 at 08:25
  • 6
    This worked. I was trying to restore a backup to a side database, but my main database went into a restoring state for some reason. This actually recovered my DB. Thanks a bunch! – Aravindh Jun 09 '14 at 21:07
  • 1
    You saved my day. Buggy MSSQL. Even reboot didn't help – Sergey Berezovskiy Nov 14 '14 at 12:06
  • For me, it just keeps running. – Panzercrisis Jun 12 '15 at 13:45
  • 2
    Some SSMS restore wizard defaults will leave the source DB in restoring state such that you can continue restoring various backups or logs with no fear of users, and this command is proper way to return the DB to normal once you are done. – Tim Lehner Aug 07 '15 at 21:47
  • Confirmed works on SQL 2008 std running on Server 2012. Thank you. – Patrick Sep 30 '15 at 14:19
  • 1
    @Panzercrisis mine remained as 'Running...' even after I refreshed the screen a few times. I eventually tried to take it offline which worked fine and bringing it back on line worked. I suspect all I needed to do was close and open SQL Studio to force a refresh. – Patrick Sep 30 '15 at 14:21
  • 1
    OP clearly states that `WITH RECOVERY` option failed. – Salman A Apr 27 '17 at 12:35
  • Executing this query worked for me... I think. I ran the query within SQL Server Management Studio (SSMS). The output of the query indicated success. However, the database still displayed its "Restoring..." status. I closed and relaunched SSMS; then the database was OK again. – Mike Finch Sep 20 '17 at 19:10
  • Worked for me, but I had to restart the SQL server first. – Michal B. Oct 17 '17 at 07:24
  • Thank you - this just helped me greatly on an important production server. – Manachi Mar 23 '18 at 02:18
  • This command fixed it for me. My database was stuck in restore because I restored it to a different name to make a copy and SQL marked the original as restoring. – Paul McCarthy Jun 20 '19 at 10:58
  • Perfect..!!! was facing issues while restoring and resolved using the above statement. thank you!! – Haseeb May 30 '20 at 19:52
  • It works me, but can someone explain what does that query does? – Wibisono Indrawan Sep 29 '20 at 07:20
474

You need to use the WITH RECOVERY option, with your database RESTORE command, to bring your database online as part of the restore process.

This is of course only if you do not intend to restore any transaction log backups, i.e. you only wish to restore a database backup and then be able to access the database.

Your command should look like this,

RESTORE DATABASE MyDatabase
   FROM DISK = 'MyDatabase.bak'
   WITH REPLACE,RECOVERY

You may have more sucess using the restore database wizard in SQL Server Management Studio. This way you can select the specific file locations, the overwrite option, and the WITH Recovery option.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
John Sansom
  • 41,005
  • 9
  • 72
  • 84
  • 3
    I've never had to use the recovery statement when doing what he is doing. WITH REPLACE should suffice. – Sam Feb 06 '09 at 20:23
  • 8
    Yes, I was using NORECOVERY but the restore process hangs. Using WITH RECOVERY, REPLACE it doesn't hang the process anymore – Junior Mayhé Sep 16 '09 at 19:26
  • This solved my problem. We had a SAN failure in the middle of a restore and this was a quick and clean solution. – Registered User Sep 21 '09 at 19:21
  • I had a similar problem today with a SQL Server 2005 database. In my case, I had to add ',RESTART' to the WITH clause, to solve the issue. It was giving me an error message stating that previous operation wasn't successful. – XpiritO Sep 05 '11 at 15:10
  • I distribute updates to our database in the form of backups that replace the old ones, but the users can install it to any location on their hard drive (not my idea), which means I need to Exec SP_HelpFile from old database before running Restore With Move, which I can't do if it's already stuck in a restore. Is there any way to use the Master database to get its filenames? Right now my only solution is to delete and reinstall. – Patrick Sep 21 '11 at 19:57
  • I have the same problem running this command with PHP PDO driver from microsoft. however when running with microsoft sql server management studio It works just fine. Any ideas about the problem ? – channa ly Jan 29 '12 at 02:13
  • `WITH REPLACE, RECOVERY, RESTART` and still same error ("The database cannot be recovered because the log was not restored."). Guess I drop the DB... [later] that worked of course, but I also had to delete the checkpoint log file that was left over. – ErikE Jul 30 '12 at 19:05
  • @JohnSansom Sure, using the restore option in the SQL Management Studio is the most guaranteed way to restore a database, but sometimes, people distribute express editions of SQL Server with no management studio (like our company) and need to provide our own tools to perform these operations. – Jerry Dodge Dec 22 '12 at 01:07
  • @JohnSansom do i need to kill the spid of the restore that is stuck first? – FistOfFury Jun 25 '13 at 22:17
  • 3
    @FistOfFury If a previous restore operation on the same database is in a suspended/sleeping state then yes. Simply stopping/cancelling the in process restore should have the same effect. – John Sansom Jun 29 '13 at 16:35
  • Using SQL Management Studio mitigates many issues like this except the tool doesn't accept/manage UNC paths so restoring a database over the network will ultimately involve use of a SQL command and solutions like this one. – John K Jul 22 '14 at 21:48
  • In my case, furthermore, I need to drop database (and lost all data from it) and restoring again – deldev Nov 23 '15 at 17:40
  • The link shown in the answer is moved here https://exploresql.com/2016/09/06/issue-in-recovering-a-database-that-is-in-the-restoring-state-reference/ – Madhivanan Oct 16 '18 at 11:36
112

Here's how you do it:

  1. Stop the service (MSSQLSERVER);
  2. Rename or delete the Database and Log files (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data...) or wherever you have the files;
  3. Start the service (MSSQLSERVER);
  4. Delete the database with problem;
  5. Restore the database again.
Zoe
  • 27,060
  • 21
  • 118
  • 148
Tipu Delacablu
  • 1,153
  • 1
  • 7
  • 2
  • Tipu, thanks for that. I had a similar problem to the original poster, but it was caused by the server running out of disk space whilst restoring and so caused a permanent restoring state. – Pauk May 22 '09 at 14:44
  • 9
    Why not just drop the database? That way you don't have to stop the service. – ErikE Jul 30 '12 at 19:10
  • 9
    @ErikE For me, SQL server said it can't drop a database in the middle of a restore, even though it wasn't really restoring.... – Erik Philips Apr 15 '13 at 17:41
  • @ErikPhilips In that case I suppose one is back to stopping the service. I wonder if that happens every time or only in certain cases of the stuck-restore problem. – ErikE Apr 15 '13 at 17:48
  • In my instance, I ran out of HD space during a restore. After, deleting more than enough files, I stopped and restarted my SQL service, but the DB was stuck restoring and never finished. (3 days for a 2gb restore, I just wanted to make sure). This was the only solution that seemed to work in my case. – Erik Philips Apr 15 '13 at 17:53
  • 8
    In my case, it was sufficient to drop the database which was hanging in state "Restoring..." with the SQL command `drop database ` in a query window. Then I right-clicked on *Databases* and selected *Refresh* which removed the entry in Management Studio. Afterwards I did a new restore which worked fine (**note** that bringing it offline did not work, a restart of the SQL service did not work, a server reboot did not work as well). – Matt Jun 23 '16 at 14:51
  • This was the solution that fixed things for me! I managed to get myself into this state by restoring an old version of my database to a different database name (so I could do some work on upgrade scripts); the restore to the new database worked but somehow had the side-effect of leaving the original database stuck in the restoring state. – Chris Bargh Feb 10 '17 at 01:32
  • I used a slight variation on this procedure: 1) copy MDF/LDF files from Data folder to a temp folder, 2) delete database via Management Studio _NB: this causes MDF/LDF files to be deleted from the Data folder_, 3) copy MDF/LDF files back from temp to Data folder, 4) in Mgmt Studio, right-click Databases and Attach the MDF/LDF files, thus restoring the database. – Chris Bargh Feb 10 '17 at 03:27
  • I second this answer. Works for me SQL 2014. – Andez Sep 08 '17 at 09:22
  • @Matt's comment helped, did a drop database on query window. Had to logout and log back in to remove the db from db list in SSMSE. – Jimson James Jul 18 '18 at 15:32
  • @JimsonKannantharaJames - seems it helped other people too, so I [promoted it to an answer.](https://stackoverflow.com/a/51405958/1016343). – Matt Jul 18 '18 at 15:40
  • For me, I did not have to restore the database. Reattaching the mdf did the trick for me. – d.i.joe Oct 16 '19 at 11:14
92

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.

TT.
  • 15,774
  • 6
  • 47
  • 88
Demetris Leptos
  • 1,560
  • 11
  • 12
  • 2
    Worked perfectly - without needing to tear it down and up again. 3 Dbs of 80+ Gb each takes a while ! Thanks! – Christer Jan 24 '17 at 12:37
  • 1
    I almost done it on production environment. I tried it on local first, ended up in this same situation and found your comment. Lesson learned: Use scripts and don't trust SSMS in important situations. – Mariusz Jul 25 '17 at 13:48
  • 1
    I got this issue when restoring a copy-only file back-up of a database to a new database. The original database showed the error. This solution worked and the response I got was _"RESTORE DATABASE successfully processed 0 pages in 0.263 seconds (0.000 MB/sec)."_, so it seems that SQL Server was just confused about the state of the database. – R. Schreurs Oct 06 '17 at 09:24
  • 1
    Worked for me but only when I removed the double-quotes -- I just had [MY_DB_NAME] as the parameter. – StackOverflowUser Apr 22 '18 at 22:06
  • 1
    Worked immediately. Tks for the tip. Easiest solution – FunMatters May 02 '22 at 11:02
92

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.

rageit
  • 3,513
  • 1
  • 26
  • 38
Hans
  • 929
  • 6
  • 2
  • 6
    Especially useful when you've already restored the database but forgot the RECOVERY option... – JBickford Mar 18 '11 at 20:31
  • 3
    This was all I needed to get it to leave the "Restoring" state after restoring a backup of this database to a different DB name. Thanks a bunch. – Sean May 26 '15 at 17:55
39

OK, I have similar problem and exactly as it was in case of Pauk, it was caused by the server running out of disk space while restoring and so caused a permanent restoring state. How to end this state without stopping SQL Server services?

I have found a solution :)

Drop database *dbname*
ErikE
  • 48,881
  • 23
  • 151
  • 196
33

WITH RECOVERY option is used by default when RESTORE DATABASE/RESTORE LOG commands is executed. If you're stuck in "restoring" process you can bring back a database to online state by executing:

RESTORE DATABASE YourDB WITH RECOVERY
GO

If there's a need for multiple files restoring, CLI commands requires WITH NORECOVERY and WITH RECOVERY respectively - only the last file in command should have WITH RECOVERY to bring back the database online:

RESTORE DATABASE YourDB FROM DISK = 'Z:\YourDB.bak'
WITH NORECOVERY
GO
RESTORE LOG YourDB FROM DISK = 'Z:\YourDB.trn'
WITH RECOVERY
GO

You can use SQL Server Management Studio wizard also:

enter image description here

There is also virtual restoring process, but you'll have to use 3rd party solutions. Usually you can use a database backup as live online database. ApexSQL and Idera has their own solutions. Review by SQL Hammer about ApexSQL Restore. Virtual restoring is good solution if you're dealing with large numbers of backups. Restore process is much faster and also can save a lot of space on disk drive. You can take a look on infographic here for some comparison.

Marko Krstic
  • 629
  • 6
  • 5
26

Right Click database go to Tasks --> Restore --> Transaction logs In the transactions files if you see a file checked, then SQL server is trying to restore from this file. Uncheck the file, and click OK. Database is back .....

this solved the issue for me, hope this helps someone.

Maverick HT
  • 427
  • 5
  • 9
24

This may be fairly obvious, but it tripped me up just now:

If you are taking a tail-log backup, this issue can also be caused by having this option checked in the SSMS Restore wizard - "Leave source database in the restoring state (WITH NORECOVERY)"

enter image description here

TrailJon
  • 461
  • 4
  • 9
  • 8
    If you are in this state, then your best bet is to: 1. Right-click the database, go to Tasks->Restore->Transaction Logs 2. Find the backup file that was used for the Tail Log back up 3. Restore the backup The restore should succeed and bring the database back online. – Ryan Gross Feb 16 '15 at 17:34
17

I figured out why.

If the client who issued the RESTORE DATABASE command disconnects during the restore, the restore will be stuck.

It's odd that the server, when told to restore a database by a client connection, will not finish the restore unless the client stays connected the entire time.

Drew Gaynor
  • 8,292
  • 5
  • 40
  • 53
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 12
    All SQL Commands require that the client stay connected the entire time. – mrdenny Aug 28 '09 at 07:12
  • 2
    @mrdenny: i would have assumed that changes get undone when a client disconnects. – Ian Boyd Aug 28 '09 at 14:28
  • 1
    I have the same problem running this command with PHP PDO driver from microsoft. however when running with microsoft sql server management studio It works just fine. I wonder how to make my php application connected the entire time ? – channa ly Jan 29 '12 at 02:52
  • Happened here also, DB stuck in restore/single-user after possible connection break. Killed all other SPIDs from new session but still stuck. Was able to drop database as solution. – crokusek Aug 03 '12 at 17:25
10

this one did work :

http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/8dd1b91d-3e14-4486-abe6-e3a550bfe457

I had a situation where my database showed restoring state and I couldn't run any queries and couldn't connect with our software.

What I did to get out of this situation is:

  1. Stop all SQL related services from windows services.

  2. I opened the DATA folder where the Ldf and Mdf files resides in the SQL directory, normally its like : "C:\Program Files***********\MSSQL\DATA

  3. Then I copied both the Ldf and Mdf files of the database: [db name].mdf and [db name]_log.ldf

I copied both of these files to another folder.

  1. Then I started all the SQL related services (in step 1) again from windows services.

  2. Started my MS SQL Management studio with normal login.

  3. Right click on the culprit database and hit DELETE (to delete the database at all).

  4. All the LDF and MDF files related to this database have gone from DATA folder (mentioned in step 2).

  5. Created a new database with the same name (same name of the one I deleted in step 6 - the culprit database).

  6. Then [database name]->right click -> tasks -> Take Offline.

  7. I then Copied both the files (from step 3) back to the DATA folder (step 2).

  8. [database name]->right click -> tasks -> Bring Online.

nathanchere
  • 8,008
  • 15
  • 65
  • 86
Ameen Abuhilal
  • 101
  • 1
  • 2
9

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
Ashkan S
  • 10,464
  • 6
  • 51
  • 80
9

In my case, it was sufficient to drop the database which was hanging in state "Restoring..." with the SQL command

 drop database <dbname> 

in a query window.

Then I right-clicked on Databases and selected Refresh which removed the entry in the SQL Server Management Studio (SSMS). Afterwards I did a new restore which worked fine.


(Note that bringing it offline did not work, a restart of the SQL service did not work, a server reboot did not work as well).

Matt
  • 25,467
  • 18
  • 120
  • 187
8

Use the following command to solve this issue

RESTORE DATABASE [DatabaseName] WITH RECOVERY
Sumant Singh
  • 904
  • 1
  • 14
  • 16
4

In my case I just Right Click on Database then Task-->Restore-->Database-->Ok and everything became fine.

Shaiwal Tripathi
  • 601
  • 1
  • 12
  • 32
3

I have had this problem when I also recieved a TCP error in the event log...

Drop the DB with sql or right click on it in manager "delete" And restore again.

I have actually started doing this by default. Script the DB drop, recreate and then restore.

ZeusT
  • 515
  • 2
  • 8
3

By default, every RESTORE DATABASE comes with RECOVERY set up. The 'NORECOVERY' options, basically tells the SQL Server that the database is waiting for more restore files (could be a DIFF file and LOG file and, could include tail-log backup file, if possible). The 'RECOVERY' options, finish all transactions and let the database ready to perform transactions.

So:

  1. if your database is set up with SIMPLE recovery model, you can only perform a FULL restore with NORECOVERY option, when you have a DIFF backup. No LOG backup are allowed in SIMPLE recovery model database.
  2. Otherwise, if your database is set up with FULL or BULK-LOGGED recovery model, you can perform a FULL restore followed by NORECOVERYoption, then perform a DIFF followed by NORECOVERY, and, at last, perform LOG restore with RECOVERY option.

Remember, THE LAST RESTORE QUERY MUST HAVE RECOVERY OPTION. It could be an explicit way or not. In therms of T-SQL, the situation:

1.

 USE [master]
    GO
    RESTORE DATABASE Database_name 
    FROM DISK = N'\\path_of_backup_file.bak WITH FILE = 1, [REPLACE],NOUNLOAD, 
    RECOVERY -- This option could be omitted.
    GO

WITH REPLACE option must be used with caution as it can lead to data loss

Or, if you perform a FULL and DIFF backup, you can use this

   USE [master]
    GO
    RESTORE DATABASE Database_name
      FROM DISK = N'\\path_of_backup_file.bak' WITH FILE = 1, 
       NOUNLOAD,NORECOVERY
    GO
    RESTORE DATABASE Database_name
      FROM DISK =N'\\path_of_**diff**backup_file.bak' WITH FILE = 1, 
     NOUNLOAD, RECOVERY
    GO

 2. USE [master]
    GO
   -- Perform a Tail-Log backup, if possible. 
   BACKUP LOG Database_name
   GO
   -- Restoring a FULL backup
   RESTORE DATABASE Database_name
    FROM DISK = N'\\path_of_backup_file.bak' WITH FILE = 1, 
     NOUNLOAD,NORECOVERY
  GO 
  -- Restore the last DIFF backup
  RESTORE DATABASE Database_name
    FROM DISK = N'\\path_of_DIFF_backup_file.bak' WITH FILE = 1,
     NORECOVERY,NOUNLOAD
  GO
  -- Restore a Log backup
  RESTORE LOG Database_name
    FROM DISK = N'path_of_LOG_backup_file.trn' WITH FILE = 2,
    RECOVERY, NOUNLOAD
  GO

Of course, you can perform a restore with the option STATS = 10 that tells the SQL Server to report every 10% completed.

If you prefer, you can observe the process or restore in real-time based query. As follow:

USE[master]
GO
SELECT session_id AS SPID, command, a.text AS Query, start_time, percent_complete, dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time 
    FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a 
        WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
GO

Hope this help.

Phil3992
  • 1,059
  • 6
  • 21
  • 45
BMDaemon
  • 61
  • 3
2

There can also be problem deleting a stuck database if snapshot is enabled. For me this worked:

  1. First I followed Tipu Delacablu steps (read a few posts up)
  2. run command: drop database [your database], which will give you an error telling you the name of the snapshot database
  3. run command: drop database [snapshot database], and then run the command in step 2 again.
Community
  • 1
  • 1
1

I have got the MyDbName (Restoring...) case because of SQL Express licensed limit.

In the log file, I found this:

CREATE DATABASE or ALTER DATABASE failed because the resulting cumulative database size would exceed your licensed limit of 10240 MB per database.

So if you are trying to restore a bigger database, you need to switch your SQL Express server to Developer edition for instance.

Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
1

Have you tried running a VERIFY ONLY? Just to make sure it's a sound backup.

http://msdn.microsoft.com/en-us/library/ms188902.aspx

Sam
  • 7,543
  • 7
  • 48
  • 62
1

What fixed it for me was

  1. stopping the instance
  2. creating a backup of the .mdf and .ldf files in the data folder
  3. Restart the instance
  4. delete the database stuck restoring
  5. put the .mdf and.ldf files back into the data folder
  6. Attach the instance to the .mdf and .ldf files
ChadJPetersen
  • 383
  • 3
  • 17
1

Ran into a similar issue while restoring the database using SQL server management studio and it got stuck into restoring mode. After several hours of issue tracking, the following query worked for me. The following query restores the database from an existing backup to a previous state. I believe, the catch is the to have the .mdf and .log file in the same directory.

RESTORE DATABASE aqua_lc_availability
FROM DISK = 'path to .bak file'
WITH RECOVERY
Ujjwal
  • 71
  • 7
0
  1. Let check and run SQL Agent Service firstly.
  2. Using following T-SQL:

    SELECT filename FROM master.sys.sysaltfiles WHERE dbid = DB_ID('db_name');

  3. Using T-SQL continuously:

    RESTORE DATABASE FROM DISK = 'DB_path' WITH RESTART, REPLACE;

Hope this help!

0

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
earthling42
  • 916
  • 10
  • 15
0

I had the same issue... although I do not know why my database experienced this problem as my drive was not full... It's like it got corrupted or something. I tried all of the above none of them fully worked, I especially thought the suggestion to stop the service and deleting the mdf and ldf files would work... but it still froze up on restore?

I ended up resolving this by deleting the files as mentioned but instead of trying to restore the DB again I copied over fresh .mdf and .ldf files and Attached these using the Front End Attachment wizard. Relief, it worked!!

It took FOREVER to copy over the new files as I am using a Virtual Machine... so copying and pasting using the clipboard took like an hour itself so I would only recommend this as a last attempt.

Anthony Griggs
  • 1,469
  • 2
  • 17
  • 39
0
RESTORE DATABASE {DatabaseName}
   FROM DISK = '{databasename}.bak'
   WITH REPLACE, RECOVERY
Yunnosch
  • 26,130
  • 9
  • 42
  • 54
Rony Barua
  • 93
  • 1
  • 5
  • Please point out the additional insight this answer provides when compared to the older, accepted and highly upvoted answer. That would help to avoid the impression of having just copied it in the hope of getting reputation. Also, code-only answers (which is the main visible difference) are not appreciated here, because they give the wrong impression that StackOverflow is a free code writing service, – Yunnosch May 09 '19 at 06:12
  • I fixed the formatting, just to make the similarity to the older answer more obvious. But you could learn to do that here https://stackoverflow.com/editing-help in case you try to make more easily readable answers in the future. – Yunnosch May 09 '19 at 06:14
0

If you want to restore an SQL Server database from a backup file, you can use the following script:

RESTORE DATABASE [MyDatabase] -- which database to restore
FROM DISK = N'X:\MyDatabase.bak' -- location of the database backup
WITH 
    FILE = 1, -- restore from a backup file
    -- declare where the file groups should be located (can be more than two)
    MOVE N'MyDatabase_Data' TO N'D:\SSDPATH\MyDatabase.mdf',
    MOVE N'MyDatabase_Log' TO N'E:\HDDPATH\MyDatabase.ldf',
    -- Tape option; only relevant if you backup from magnetic tape
    NOUNLOAD,
    -- brings the database online after the database got restored
    -- use this option when you don't want to restore incremental backups
    -- use NORECOVERY when you want to restore differential and incremental backup files
    RECOVERY,
    -- replace existing database with the backup 
    -- deletes the existing database
    REPLACE, 
    -- print log message for every 1 percent of restore
    STATS = 1;
MovGP0
  • 7,267
  • 3
  • 49
  • 42
0

This is an old issue that keeps coming up all the time with SQL Server, even the latest 2019 version! I don't know why Microsoft have left this pain take hold for so long and allowed their MSSQL engine to continue behaving this way. Never the less, I propose another possible solution for those that tried the RESTORE DATABASE WITH RECOVERY option and it still didn't work.

Log into the server itself and fire up the default SSMS program on the actual database server. Next go to the "recovery" database and DELETE it. Done. Problem gone. If you needed to keep it, copy the MDF file and rename it and attach it as a new database. Worked for me on SQL Server 2008 R2.

Fandango68
  • 4,461
  • 4
  • 39
  • 74
0

This problem occurred for me today on a VM SQL Server. I attempted to restore a 1.8GB Database and it was stuck at 0% with ASYNC_IO_COMPLETION.

I tried multiple times, moving the .bak file to the same drive I was restoring to; even trying to restore another unrelated database that was <400MB in size.

I tried everything on this thread, with no luck.

Then I came across Restore stuck in ASYNC_IO_COMPLETION on DBA and the answer worked for me.

Enable Instant File Initialization and restart SQL Server, then retry the restore. The SSMS GUI showed a percentage progress almost instantly, as did:

Select percent_complete,* From sys.dm_exec_requests

My guess is that the storage behind the VM is very slow, or at fault.

Lazlow
  • 3,241
  • 3
  • 21
  • 13