我备份了一个数据库:

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

然后试图恢复它:

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

现在数据库处于还原状态。

有些人推测,这是因为备份中没有日志文件,需要使用以下方法前滚:

RESTORE DATABASE MyDatabase
WITH RECOVERY 

当然,这是行不通的:

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.

在灾难性的情况下,你想要的是一个无法工作的恢复。


备份包含数据文件和日志文件:

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

当前回答

右键单击数据库,进入“任务——>恢复——>事务日志” 在事务文件中,如果您看到一个文件被选中,则SQL server正在尝试从该文件恢复。 取消选中该文件,并单击OK。数据库恢复.....

这为我解决了问题,希望这能帮助到别人。

其他回答

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]"

这解决了问题。一开始我遇到了麻烦,因为数据库名称包含特殊字符。我通过在周围添加双引号来解决这个问题-单引号将不起作用,给出“错误的语法接近……”错误。

这是我尝试解决这个问题(数据库处于恢复状态)的最小解决方案,我希望它可以应用到更多的情况。

我也有同样的问题……虽然我不知道为什么我的数据库遇到这个问题,因为我的驱动器没有满…好像是被损坏了什么的。我尝试了以上所有的,没有一个完全工作,我特别认为建议停止服务和删除mdf和ldf文件将工作…但在恢复时仍然死机?

我最终通过删除上面提到的文件来解决这个问题,但我没有尝试再次恢复DB,而是复制了新鲜的.mdf和.ldf文件,并使用前端附件向导附加这些文件。如释重负,它起作用了!!

它花了永远复制的新文件,因为我正在使用虚拟机…所以用剪贴板复制粘贴本身就花了一个小时,所以我只推荐这是最后一次尝试。

好吧,我有类似的问题,就像在Pauk的情况下一样,这是由服务器在恢复时耗尽磁盘空间引起的,因此导致了永久恢复状态。 如何在不停止SQL Server服务的情况下结束此状态?

我找到了一个解决方案:)

Drop database *dbname*

如果您想从备份文件恢复SQL Server数据库,可以使用以下脚本:

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;

我有一个。在我的数据库名称中,查询没有工作,因为(在'.'附近说不正确的语法)然后我意识到我需要一个括号的名称:

RESTORE DATABASE [My.DB.Name] WITH RECOVERY