DMO由一个动态链接库SQLDMO.DLL文件(在C:\Program Files\Microsoft SQL Server\80\Tools\Binn目录下)
using System;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main(string[] args)
{
DbBackup();
}
///<summary>
/// 数据库备份
///</summary>
public static void DbBackup()
{
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(@".\SQL2005", "sa", "123456");
Console.WriteLine("正在连接服务器");
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = "SMMM";
oBackup.Files = @"d:\SMMM.bak";
oBackup.BackupSetName = "SMMM";
oBackup.BackupSetDescription = "数据库备份";
oBackup.Initialize = true;
Console.WriteLine("正在备份");
oBackup.SQLBackup(oSQLServer);
Console.WriteLine("备份完成");
}
//catch
// {
// throw;
// }
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
oSQLServer.DisConnect();
}
}
}