Back to list
Views:   8K
Replies:  0
Archived

Restoring a Database from a .bak file for a Specified Date given

Hello, every one. I have created some application which will take Backups of a Database in Full and Differential modes in C#.net to the Sql Server 2008 Database, now if i want to make the Restore not entire database, but only the data which is modified on a Particular date. Is it possible to do. I have provided my code samples, can any one help me.
private void BackupDataBaseFull(Server MyServer,Database MyDataBase,string DestinationPath,string Type)
         {
             try
             {
                 Backup backDB = new Backup();
                 backDB.Action = BackupActionType.Database;
                 backDB.Database = MyDataBase.Name;
                 backDB.Devices.AddDevice(DestinationPath, DeviceType.File);
                 backDB.BackupSetName = "Sql Database Backup Full";
                 backDB.BackupSetDescription = "Sql Database Backup - Full Backup";
                 backDB.ExpirationDate = DateTime.Now.AddDays(5);
                 backDB.Initialize = false;
                 if (Type == "Manual")
                 {
                     progressBar1.Value = 0;
                     backDB.PercentComplete += new PercentCompleteEventHandler(bd_PercentComplete);
                     backDB.Complete += new ServerMessageEventHandler(bd_Complete);
                 }
                 else if (Type == "Automatic")
                 {
                     backDB.PercentComplete += CompletionStatusInPercent;
                     backDB.Complete += Backup_Completed;
                 }
                 backDB.SqlBackup(MyServer);
             }
             catch (Exception ex)
             {
                   MessageBox.Show(ex.ToString(), "SqlBackupRestore", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }

 
private void BackupDataBaseDifferential(Server MyServer, Database MyDataBase, string DestinationPath, string Type)
         {
             try
             {
                 Backup backDB = new Backup();
                 backDB.Action = BackupActionType.Database;
                 backDB.Database = MyDataBase.Name;
                 backDB.Devices.AddDevice(DestinationPath, DeviceType.File);
                 backDB.BackupSetName = "Sql Database Backup Differential";
                 backDB.BackupSetDescription = "Sql Database Backup - DifferentialType";
                 backDB.ExpirationDate = DateTime.Now.AddDays(5);
                 backDB.Initialize = false;
                 backDB.Incremental = true;
                 if (Type == "Manual")
                 {
                     progressBar1.Value = 0;
                     backDB.PercentComplete += new PercentCompleteEventHandler(bd_PercentComplete);
                     backDB.Complete += new ServerMessageEventHandler(bd_Complete);
                 }
                 else if (Type == "Automatic")
                 {
                     backDB.PercentComplete += CompletionStatusInPercent;
                     backDB.Complete += Backup_Completed;
                 }
                 backDB.SqlBackup(MyServer);
             }
             catch (Exception ex)
             {
                   MessageBox.Show(ex.ToString(), "SqlBackupRestore", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }

 
private void RestoreDataBase(Server MyServer, Database MyDataBase, string DevicePath, string Type)
         {
             try
             {
                 progressBar1.Value = 0;
                 Restore restoreDB = new Restore();
                 restoreDB.Action = RestoreActionType.Database;
                 restoreDB.Database = MyDataBase.Name;
                 restoreDB.Devices.AddDevice(DevicePath, DeviceType.File);
                 restoreDB.ReplaceDatabase = true;
                 restoreDB.NoRecovery = true;
                 restoreDB.PercentComplete += new PercentCompleteEventHandler(rstDatabase_PercentComplete);
                 restoreDB.Complete += new ServerMessageEventHandler(rstDatabase_Complete);
                 restoreDB.SqlRestore(MyServer);
             }
             catch (Exception ex)
             {
                   MessageBox.Show(ex.ToString(), "SqlBackupRestore", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }

 
Kalyan Kumar, Apr 09, 2011


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.2.2