我们知道,用SQLDMO可以实现对数据库的备份与恢复,下面给出简单的实现方法。
首先需要添加对SQLDMO引用。
1.实现数据库的备份:
1/**//// <summary>
2 /// 数据库备份
3 /// </summary>
4 /// <returns>备份是否成功</returns>
5 public bool DbBackup()
6 {
7 string path = CreatePath();
8 SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
9 SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
10 try
11 {
12 oSQLServer.LoginSecure = false;
13 oSQLServer.Connect(server,uid, pwd);
14 oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
15 oBackup.Database = database;
16 oBackup.Files = path;
17 oBackup.BackupSetName = database;
18 oBackup.BackupSetDescription = "数据库备份";
19 oBackup.Initialize = true;
20 oBackup.SQLBackup(oSQLServer);
21
22 return true;
23 }
24 catch(Exception ex)
25 {
26 return false;
27 throw ex;
28 }
29 finally
30 {
31   |