用C#编写的数据库备份及恢复

时间:2011-12-07 06:27:11
【文件属性】:

文件名称:用C#编写的数据库备份及恢复

文件大小:3KB

文件格式:TXT

更新时间:2011-12-07 06:27:11

用c#备份数据库

#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(); } }


网友评论