gpt4 book ai didi

c# - SMO 恢复花了很长时间

转载 作者:行者123 更新时间:2023-11-30 17:52:53 25 4
gpt4 key购买 nike

我使用这个 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 时,恢复过程花了很长时间

enter image description here

我用这个来备份数据库并且能够备份数据库

            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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com