日期:2009-10-16 浏览次数:20397 次
string selfName = “D:\NorthwindBak“;
string deviceName = “NorthwindBak“;
string remark = "备份测试";
//◆数据备份:
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
oBackup.Action = 0 ;
oBackup.Initialize = true ;
SQLDMO.BackupSink_PercentCompleteEventHandler pceh = new SQLDMO.BackupSink_PercentCompleteEventHandler(Step);
oBackup.PercentComplete += pceh;
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(Common.MySettings.SqlServerName, "sa", "");
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = "Northwind";//数据库名
oBackup.Files = selfName;//文件路径
oBackup.BackupSetName = deviceName;//备份名称
oBackup.BackupSetDescription = remark;//备份描述
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
}
catch(System.Exception ex)
{
Common.ShowMsg("数据备份失败:\n" + ex.ToString());
}
finally
{
oSQLServer.DisConnect();
}
//------------------------------------------------------------------------------------
this.label1.Visible = false;
this.pBar1.Visible = false;
this.Cursor = Cursors.Default;
}
/// <summary>
/// 显示备份进度条
/// </summary>
private void Step(string message,int percent)
{
this.pBar1.Value = percent ;
}
◆数据还原 :
/// <summary>
/// 还原数据库
/// </summary>
private void btnRestore_Click(object sender, System.EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
this.label1.Text = " 正在进行档案库的数据还原,这可能需要几秒到几十的时间,请稍候...";
this.label1.Visible = true;
this.label1.Refresh();
this.pBar1.Visible = true;
//------------------------------------------------------------------------------------
string fileName = "NorthwindBak";
string filePath = "D:\NorthwindBak";
string remark = "备份测试";
SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
oRestore.Action = 0 ;
SQLDMO.RestoreSink_PercentCompleteEventHandler pceh = new S