Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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

This [Link] contains the SQL script to restore multiple database from one .bak file. You can use this query to execute from your application.
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900