从一个.BAK还原多个数据库 [英] Restore multi database from one .BAK
本文介绍了从一个.BAK还原多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我准备使用Microsoft.SqlServer.Management.Smo类在C#上还原应用程序,以从SQL Server备份文件(* .BAK)还原数据库,如下所示:
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();
}
如果我使用一个BAK文件还原一个数据库,则此代码可以正常工作.
但是我只想从一个备份文件(例如:sale.bak,该文件有2个数据库,包括KHR和USD)中还原2个或更多数据库(例如:SaleKHR,SaleUSD),请帮助我...谢谢..
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..
推荐答案
此 [链接]包含用于还原多个一个.bak文件中的数据库.您可以使用此查询从您的应用程序执行.
This [Link] contains the SQL script to restore multiple database from one .bak file. You can use this query to execute from your application.
这篇关于从一个.BAK还原多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文