资源介绍
#region SQL数据库备份
///
/// SQL数据库备份
///
/// SQL服务器IP或(Localhost)
/// 数据库登录名
/// 数据库登录密码
/// 数据库名
/// 备份到的路径
public static void SQLBACK(string ServerIP,string LoginName,string LoginPass,string DBName,string BackPath)
{
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(ServerIP, LoginName, LoginPass);
oBackup.Database = DBName;
oBackup.Files = BackPath;
oBackup.BackupSetName = DBName;
oBackup.BackupSetDescription = "数据库备份";
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
finally
{
oSQLServer.DisConnect();
}
}