我需要在 TreeView 中遍历所有数据库,然后选择 TreeNode 作为要恢复的数据库名称。如果我只选择 1、2 或 3 个数据库来恢复,我的代码可以正常工作。但是,如果我选择许多数据库,它将被挂起。
请检查我的代码并帮助我..
foreach (TreeNode tn in trvList.Nodes)
{
if (tn.Checked == true)
{
strFileName = GetFileTorestor(strRealdb);//Check File Directory to restore example : C:data\tn.text.
if (strFileName != "")
{
RestoreDatabase(res, tn);
}
else
{
strErorLog += "\r\n -" + tn.Text;
blIsEror = true;
MessageBox.Show("Database " + tn.Text + " has not found!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
/// <summary>
/// Restore database according to treenode selected.
/// </summary>
/// <param name="res"></param>
/// <param name="tn"></param>
private void RestoreDatabase(Restore res,TreeNode tn)
{
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.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
res.PercentCompleteNotification = 5;
res.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);
res.SqlRestore(DBHelper.Server);
stLog += "\r\n " + tn.Text + " from file " + strFileName;//Record database name already restore to log text
txtLog.Text = stLog;
txtLog.Refresh();
}