我使用此SMO还原备份:

        Server myServer = new Server(@"PC-1\Instance1");
        Restore restoreDB = new Restore();
        restoreDB.Database = "Sample";
        restoreDB.Action = RestoreActionType.Database;
        restoreDB.Devices.AddDevice(@"D:\Sample.bak", DeviceType.File);
        restoreDB.ReplaceDatabase = true;
        restoreDB.NoRecovery = true;
        restoreDB.SqlRestore(myServer);


但是当我打开SSMS时,恢复就花了很长时间



我用它来备份数据库,并能够备份数据库

            Server myServer = new Server(@"PC-1\Instance1");
            Backup bkpDBFull = new Backup();
            bkpDBFull.Action = BackupActionType.Database;
            bkpDBFull.Database = "Sample";
            bkpDBFull.Devices.AddDevice(@"D:\Sample.bak", DeviceType.File);
            bkpDBFull.BackupSetName = "Sample";
            bkpDBFull.BackupSetDescription = "Sample";
            bkpDBFull.ExpirationDate = DateTime.Today.AddDays(5);
            bkpDBFull.Initialize = false;
            bkpDBFull.SqlBackup(myServer);

最佳答案

您的代码中包含以下行:

restoreDB.NoRecovery = true;


因此,在您运行之前,数据库将永远显示为正在还原中的SSMS

RESTORE DATABASE [sample] WITH RECOVERY


或其等效的SMO,我不确定到底是什么。

关于c# - SMO永久恢复,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18025135/

10-10 07:48