Reputation: 2989
I use this SMO to restore a backup:
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);
But when I open SSMS the restoring took forever
I use this to backup database and able to backup the database
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);
Upvotes: 3
Views: 135
Reputation: 9298
You have the following line in your code:
restoreDB.NoRecovery = true;
Hence the database will stay showing as restoring in SSMS forever until you run
RESTORE DATABASE [sample] WITH RECOVERY
Or its SMO equivalent, I'm not sure exactly what that would be.
Upvotes: 1