sql数据库备份还原数据库功能实现代码
本文导语: asp.net实现的sql数据库恢复代码。 代码示例: using System; using SQLDMO; namespace EDTBackupTool { /// /// Backup 的摘要说明。 /// public class SQLTools { public static bool Backup(string backfile){ try { SQLDMO.Backup backup = n...
asp.net实现的sql数据库恢复代码。
using System;
using SQLDMO;
namespace EDTBackupTool
{
///
/// Backup 的摘要说明。
///
public class SQLTools
{
public static bool Backup(string backfile){
try
{
SQLDMO.Backup backup = new BackupClass();
SQLDMO.SQLServer server = new SQLServerClass();
server.LoginSecure = true;
server.Connect(ClientCommon.CommonFunctions.DataSource,"sa","");
backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
backup.Database = ClientCommon.CommonFunctions.Catalog;
backup.Files =backfile;
backup.BackupSetName =ClientCommon.CommonFunctions.Catalog;
backup.BackupSetDescription = "数据库备份";
backup.Initialize = true;
backup.SQLBackup(server);
return true;
}
catch(Exception ex){
ClientCommon.ExceptionRecorder.Record(ex);
return false;
}
}
public static bool RestoreDB(string strFileName)
{
SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass() ;
try
{
svr.LoginSecure=true;
svr.Connect(ClientCommon.CommonFunctions.DataSource,"sa","") ;
SQLDMO.QueryResults qr = svr.EnumProcesses(-1) ;
int iColPIDNum = -1 ;
int iColDbName = 1 ;
for(int i=1;i