SQL Server: Database stuck in “Restoring” state

前端 未结 26 1866
后悔当初
后悔当初 2020-11-28 17:09

I backed up a database:

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

And then tried to restore it

相关标签:
26条回答
  • 2020-11-28 17:46

    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.

    0 讨论(0)
  • 2020-11-28 17:47

    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.

    0 讨论(0)
  • 2020-11-28 17:47

    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.
    0 讨论(0)
  • 2020-11-28 17:50

    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.

    0 讨论(0)
  • 2020-11-28 17:50

    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.

    0 讨论(0)
  • 2020-11-28 17:52

    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.

    0 讨论(0)
提交回复
热议问题