Click here to Skip to main content
14,328,676 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear All,

I prepare Restore Application on C# to restore database from SQL server back up file ( *.BAK) using Microsoft.SqlServer.Management.Smo class as the following Code:

private void RestoreDatabase(Restore res, TreeNode tn)
      {
          blRestoreCompleted = false;
          res.Database = tn.Text;
          res.Action = RestoreActionType.Database;
          res.Devices.AddDevice(strFileName, DeviceType.File);
          res.ReplaceDatabase = true;
          this.pgrRestore.Value = 0;
          this.pgrRestore.Maximum = 100;
          res.PercentCompleteNotification = 5;
          res.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);
          res.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
          res.SqlRestore(DBHelper.Server);
          stLog += "\r\n " + tn.Text + " from file " + strFileName;//Record database name already restore to log text

          if (chkRate.Checked == true)
          {
              string ExchangeRate;
              string StepRuning;
              string ccy_date;
              CheckRateAndStep(tn,out ExchangeRate,out ccy_date,out StepRuning);
              stLog += "--CcyDate: " + ccy_date + " Rate:" + ExchangeRate + " RunStep:" + StepRuning;
          }
          txtLog.Text = stLog;
          txtLog.Refresh();
      }


If I restore one database using one BAK file, this code is working fine.
But I want to restore 2 or more database ( Ex: SaleKHR, SaleUSD ) from only one back up file(Ex: sale.bak, this file have 2 databases include KHR and USD ), Please help me...Thanks..
Posted
Updated 10-Jun-12 20:43pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

This [Link] contains the SQL script to restore multiple database from one .bak file. You can use this query to execute from your application.
   
Comments
LTMKH 11-Jun-12 3:27am
   
Thank for your help, i'm not yet understand how to use this script... Is you have any idea related to using smo class to restore?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100