c# - Restoring a Differential Backup with an SMO Restore object -


I restore the database by first restoring a full backup and then restoring a differential backup using Microsoft.SqlServer. I am trying. Management.MO Restore class full backup has been restored with the following code:

  restored myFullRestore = new restore (); MyFullRestore.Database = "DatabaseName"; MyFullRestore.Action = Restore one. Database; MyFullRestore.AddDevice (@ "C: \ BackupFile.bak", DeviceType.File); MyFullRestore.FileNumber = 1; MyFullRestore.SqlRestore (MYSERVER); // myServer is a pre-existing example of Microsoft. SQL Server. Management.MO.All  

After restoring the full backup (which completes successfully), my code to restore the differential backup is as follows:

  restored Do myDiffRestore = new restore (); MyDiffRestore.Database = "DatabaseName"; MyDiffRestore.action = Restore one. Database; MyDiffRestore.AddDevice (@ "C: \ BackupFile.bak", DeviceType.File); MyDiffRestore.FileNumber = 4; // file has many backup sets, this is the index of the set that I want to use myDiffRestore.SqlRestore (myServer); However, this code will throw a Microsoft.SqlServer.Management.Smo.FailedOperationException, with the message "Restore Server" for servername "Failed" ". Do I explicitly say this Should I restore a differential backup, and if so, how would I go about doing this? Or is there a less obvious problem?  

Updates : This Not sure whether this was originally a typo or earlier versions had it E suggests what I'm doing (or ignore to do). The form of the API, but this line for later versions

  fullRestore.AddDevice (...); < Should be / code>  

  fullRestore.Devices.AddDevice (...)  

After a little more digging, I found out that to restore the differential backup to work, the full restore requirement can not be set to true:

  // for myFullRestore Before executing SqlRestore order ... myFullRestore.NoRecovery = true;  

This specifies that there is a need to apply another transfer log, which is a different backup in this case. There is more information on this page that I found useful:


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -