C#在线备份数据库至制定目录
/// <summary>
/// 备份数据库至制定目录
/// </summary>
/// <param name="sSeverName">服务器名</param>
/// <param name="sDataBase">数据库名</param>
/// <param name="sUserName">用户名</param>
/// <param name="sPassWord">密码</param>
/// <param name="sPath">保存路径</param>
/// <returns></returns>
public static FileInfo BackUp(string sSeverName,string sDataBase,string sUserName,string sPassWord,string sPath)
{
sqldmo.BackupClass oBackup=new sqldmo.BackupClass();
sqldmo.SQLServerClass oSqlServer=new sqldmo.SQLServerClass();
oSqlServer.LoginSecure=false;
oSqlServer.Connect(sSeverName,sUserName,sPassWord);
oBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = sDataBase;
oBackup.Files = sPath;
oBackup.BackupSetName = sDataBase;
oBackup.BackupSetDescription = sDataBase+"Back";
oBackup.Initialize = true;
oBackup.SQLBackup(oSqlServer);
oSqlServer.DisConnect();
FileInfo fi = new System.IO.FileInfo(sPath);
return fi;
}
/// 备份数据库至制定目录
/// </summary>
/// <param name="sSeverName">服务器名</param>
/// <param name="sDataBase">数据库名</param>
/// <param name="sUserName">用户名</param>
/// <param name="sPassWord">密码</param>
/// <param name="sPath">保存路径</param>
/// <returns></returns>
public static FileInfo BackUp(string sSeverName,string sDataBase,string sUserName,string sPassWord,string sPath)
{
sqldmo.BackupClass oBackup=new sqldmo.BackupClass();
sqldmo.SQLServerClass oSqlServer=new sqldmo.SQLServerClass();
oSqlServer.LoginSecure=false;
oSqlServer.Connect(sSeverName,sUserName,sPassWord);
oBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = sDataBase;
oBackup.Files = sPath;
oBackup.BackupSetName = sDataBase;
oBackup.BackupSetDescription = sDataBase+"Back";
oBackup.Initialize = true;
oBackup.SQLBackup(oSqlServer);
oSqlServer.DisConnect();
FileInfo fi = new System.IO.FileInfo(sPath);
return fi;
}