Ejemplo n.º 1
0
        public bool BackupDatabase(string sFullName, string sDataBase)
        {
            bool flag = false;

            SQLDMO.Backup backup       = new BackupClass();
            SQLServer     serverObject = new SQLServerClass();

            try
            {
                serverObject.LoginSecure = false;
                serverObject.Connect(this.Server, this.UserID, this.Password);
                backup.Action               = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
                backup.Database             = sDataBase;
                backup.Files                = string.Format("[{0}]", sFullName);
                backup.BackupSetName        = sDataBase;
                backup.BackupSetDescription = string.Format("数据库备份:{0}", sDataBase);
                backup.Initialize           = true;
                backup.SQLBackup(serverObject);
                if (System.IO.File.Exists(sFullName))
                {
                    flag = true;
                }
            }
            catch (Exception exception)
            {
                Log.WriteLog(string.Format("备份数据库[{0}]:BackupDatabase(string sFullName, string sDataBase)", sDataBase), exception.Message);
                return(flag);
            }
            finally
            {
                serverObject.DisConnect();
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public bool DbBackup(string url)
        {
            Backup    oBackup    = new BackupClass();
            SQLServer oSQLServer = new SQLServerClass();
            bool      result;

            try
            {
                oSQLServer.LoginSecure = false;
                oSQLServer.Connect(this.server, this.uid, this.pwd);
                oBackup.Action               = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
                oBackup.Database             = this.database;
                oBackup.Files                = url;
                oBackup.BackupSetName        = this.database;
                oBackup.BackupSetDescription = "数据库备份";
                oBackup.Initialize           = true;
                oBackup.SQLBackup(oSQLServer);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                oSQLServer.DisConnect();
            }
            return(result);
        }
Ejemplo n.º 3
0
 public static bool DbBackup(string url)
 {
     bool flag;
     Backup backup = new BackupClass();
     SQLServer serverObject = new SQLServerClass();
     try
     {
         serverObject.LoginSecure = false;
         serverObject.Connect(ConfigurationManager.AppSettings["Server"], ConfigurationManager.AppSettings["User"], ConfigurationManager.AppSettings["Password"]);
         backup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
         backup.Database = ConfigurationManager.AppSettings["DB"];
         backup.Files = url;
         backup.BackupSetName = ConfigurationManager.AppSettings["DB"];
         backup.BackupSetDescription = "数据库备份";
         backup.Initialize = true;
         backup.SQLBackup(serverObject);
         flag = true;
     }
     catch
     {
         flag = false;
     }
     finally
     {
         serverObject.DisConnect();
     }
     return flag;
 }
Ejemplo n.º 4
0
    public bool DbBackup(string url)
    {
        bool      result    = true;
        Backup    backup    = new BackupClass();
        SQLServer sQLServer = new SQLServerClass();

        try
        {
            sQLServer.LoginSecure = false;
            string[] array = backup_BackupList.pstr.Split(new char[]
            {
                ';'
            });
            sQLServer.Connect(array[0].Split(new char[]
            {
                '='
            })[1], array[3].Split(new char[]
            {
                '='
            })[1], array[4].Split(new char[]
            {
                '='
            })[1]);
            backup.Action   = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
            backup.Database = array[1].Split(new char[]
            {
                '='
            })[1];
            url = url + array[1].Split(new char[]
            {
                '='
            })[1] + ".bak";
            backup.Files         = url;
            backup.BackupSetName = array[1].Split(new char[]
            {
                '='
            })[1];
            backup.BackupSetDescription = DateTime.Now.ToString("yyyyMMddHHmm") + "数据库备份";
            backup.Initialize           = true;
            backup.SQLBackup(sQLServer);
        }
        catch (Exception)
        {
            result = false;
            throw;
        }
        finally
        {
            sQLServer.DisConnect();
        }
        return(result);
    }
Ejemplo n.º 5
0
        private bool BackUpDb(string dbName, string bakFile, string bakSetName)
        {
            //try
            //{
            Backup oBackup = new BackupClass();

            oBackup.Action        = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
            oBackup.Database      = dbName;
            oBackup.Files         = bakFile;
            oBackup.BackupSetName = bakSetName;
            oBackup.Initialize    = true;
            oBackup.SQLBackup(sqlServer);
            return(true);
            //}
            //catch
            //{
            //    return false;
            //}
        }
Ejemplo n.º 6
0
		public string BackUpDatabase(string backuppath, string ServerName, string UserName, string Password, string strDbName, string strFileName)
		{
			SQLServer svr = new SQLServerClass();
			try
			{
				svr.Connect(ServerName, UserName, Password);
				Backup bak = new BackupClass();
				bak.Action = 0;
				bak.Initialize = true;
				bak.Files = backuppath + strFileName + ".config";
				bak.Database = strDbName;
				bak.SQLBackup(svr);
				return string.Empty;
			}
			catch(Exception ex)
			{
				string message = ex.Message.Replace("'", " ");
				message = message.Replace("\n", " ");
				message = message.Replace("\\", "/");
				return message;
			}
			finally
			{
				svr.DisConnect();
			}
		}