我使用此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);
答案 0 :(得分:1)
您的代码中包含以下行:
restoreDB.NoRecovery = true;
因此,在您运行
之前,数据库将一直显示为在SSMS中永久恢复RESTORE DATABASE [sample] WITH RECOVERY
或者它的SMO等价物,我不确定那是什么。