数据备份还原,大侠帮忙看看
这是参考别人的贴子做的数据备份还原的代码,出错...
大侠帮忙找找问题,一定给分! (SQL SERVER 2000)
private void btnRestore_Click(object sender, System.EventArgs e)
{
if(this.dgBackUpList.CurrentRowIndex < 0 || this.dtBackUpList.Rows.Count < 1)
{
Common.ShowMsg("请从列表中选择一个备份进行还原:");
return;
}
string fileName = this.dtBackUpList.Rows[this.dgBackUpList.CurrentRowIndex]["fileName"].ToString();
string filePath = this.dtBackUpList.Rows[this.dgBackUpList.CurrentRowIndex]["filePath"].ToString();
string remark = this.dtBackUpList.Rows[this.dgBackUpList.CurrentRowIndex]["remark"].ToString();
if(!System.IO.File.Exists(filePath))
{
Common.ShowMsg("该数据备份的备份文件已被移走,无法进行还原。");
return;
}
if(!Common.ShowConfirm("您确认要恢复该备份吗?"))
return;
SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
oRestore.Action = 0 ; oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
oRestore.Database = "CgFyDB";
oRestore.Files = filePath;
oRestore.FileNumber = 1;
oRestore.ReplaceDatabase = true;
oRestore.SQLRestore(oSQLServer);
}
catch(System.Exception ex)
{
Common.ShowMsg("数据还原失败:\n" + ex.ToString());
}
finally
{
oSQLServer.DisConnect();
}
}