用SQLDMO备份SQL2005数据库碰到的几个问题
用SQLDMO做SQL2005数据库备份程序,主要代码如下:SQLDMO.Backup sqldmo_backup = new SQLDMO.BackupClass();
SQLDMO.SQLServer sqldmo_sqlserver = new SQLDMO.SQLServerClass();
sqldmo_backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
//下面两句是显示进度条的状态
SQLDMO.BackupSink_PercentCompleteEventHandler pceh = new SQLDMO.BackupSink_PercentCompleteEventHandler(Step);
sqldmo_backup.PercentComplete += pceh;
//数据库名称:
sqldmo_backup.Database = "Jiamei_CS";
//备份的路径
sqldmo_backup.Files = @p_str_backuppath+@"\jiamei_cs.bak";
//备份的文件名
sqldmo_backup.BackupSetName = "Jiamei_CS";
sqldmo_backup.BackupSetDescription = "数据库备份";
sqldmo_backup.Initialize = true;
private void Step(string message, int percent)
{
progressBar1.Value = percent;
}
运行后成功了,由于这段资料是从网上找的,有几个问题想请教:
1、sqldmo_backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database是什么意思,是开始备份吗,写成sqldmo_backup.Action = 0也能运行,怎么回事?
2、sqldmo_backup.BackupSetName = "Jiamei_CS"是什么意思?备份里没作用吧?
3、sqldmo_backup.BackupSetDescription = "数据库备份"是什么,备份好后我也没找到"数据库备份"这个目录或文件,这句可以不写吧?
4、sqldmo_backup.Initialize = true有什么作用?
5、按照文章说的SQLDMO.BackupSink_PercentCompleteEventHandler pceh = new SQLDMO.BackupSink_PercentCompleteEventHandler(Step)和qldmo_backup.PercentComplete += pceh这2句加上Step函数可以显示进度条,但是我运行时进度条怎么不显示进度?
6、sqldmo_backup.Files = @p_str_backuppath+@"\jiamei_cs.bak"这句指备份的目标路径及目标文件名,现在问题是如果p_str_backuppath所代表的目标路径是长文件名,如“D:\Program Files”超过8个字符了,运行时提示无法找到这个目标,是要转成短文件名吧?