相关代码如下:
public string StrServer,StrUser,StrPassword,StrDatabase,StrBackupPath;
private SQLDMO.Backup MyBackup;
this.Load += new System.EventHandler(this.FrmBackup_Load);
MyBackup.PercentComplete += new SQLDMO.BackupSink_PercentCompleteEventHandler(MyBackup_PercentComplete); //提示出错的行
private void FrmBackup_Load(object sender, System.EventArgs e)
{
SQLDMO.SQLServer SqlServer=new SQLDMO.SQLServerClass();
SqlServer.LoginSecure=false;
SqlServer.Connect(StrServer,StrUser,StrPassword);
MyBackup=new SQLDMO.BackupClass();
MyBackup.Database=StrDatabase;
MyBackup.Action=0;
MyBackup.Files=StrBackupPath;
MyBackup.Initialize=true;
progressBar1.Value=0;
progressBar1.Maximum = 100;
MyBackup.SQLBackup(SqlServer);
progressBar1.Value = 100;
MessageBox.Show("数据库备份完成","系统消息");
}
private void MyBackup_PercentComplete(string Message, int Percent)
{
progressBar1.Value = progressBar1.Maximum * ( Percent / 100);
}
错误提示:
未处理的“System.NullReferenceException”类型的异常出现在 DbBackup.exe 中。
其他信息: 未将对象引用设置到对象的实例。
请问该怎么改??
public string StrServer,StrUser,StrPassword,StrDatabase,StrBackupPath;
private SQLDMO.Backup MyBackup;
this.Load += new System.EventHandler(this.FrmBackup_Load);
MyBackup.PercentComplete += new SQLDMO.BackupSink_PercentCompleteEventHandler(MyBackup_PercentComplete); //提示出错的行
private void FrmBackup_Load(object sender, System.EventArgs e)
{
SQLDMO.SQLServer SqlServer=new SQLDMO.SQLServerClass();
SqlServer.LoginSecure=false;
SqlServer.Connect(StrServer,StrUser,StrPassword);
MyBackup=new SQLDMO.BackupClass();
MyBackup.Database=StrDatabase;
MyBackup.Action=0;
MyBackup.Files=StrBackupPath;
MyBackup.Initialize=true;
progressBar1.Value=0;
progressBar1.Maximum = 100;
MyBackup.SQLBackup(SqlServer);
progressBar1.Value = 100;
MessageBox.Show("数据库备份完成","系统消息");
}
private void MyBackup_PercentComplete(string Message, int Percent)
{
progressBar1.Value = progressBar1.Maximum * ( Percent / 100);
}
错误提示:
未处理的“System.NullReferenceException”类型的异常出现在 DbBackup.exe 中。
其他信息: 未将对象引用设置到对象的实例。
请问该怎么改??
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货