zoukankan      html  css  js  c++  java
  • 数据库的备份与恢复

          
    数据库的备份:
      -----

    SQLServer2Class oSqlServer = new SQLServer2Class();
            oSqlServer.LoginSecure = true;
            oSqlServer.Connect(this.txtServerName.Text.Trim(), this.txtDbLoginName.Text.Trim(), this.txtPwd.Text.Trim());//数据库的名称、数据库的登录名、数据库的密码

            Backup2Class oBack = new Backup2Class();
            oBack.Database = this.txtDbName.Text.Trim();   //要备份的数据库
            oBack.Files = this.txtBackPath.Text.Trim();   //目标文件
            oBack.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
            try
            {
                oBack.SQLBackup(oSqlServer);
                Response.Write("<script>alert('备份成功!');window.location.href='backupdb.aspx'</script>");
            }
            catch
            {
                Response.Write("<script>alert('备份失败!');window.location.href='backupdb.aspx'</script>");
            }
            finally
            {
                oBack = null;
            }



    数据库的恢复:
      -----
    SQLServer2Class oSqlServer = new SQLServer2Class();
            oSqlServer.LoginSecure = true;
            oSqlServer.Connect(this.txtServerName.Text.Trim(), this.txtDbLoginName.Text.Trim(), this.txtPwd.Text.Trim()); //数据库的名称、登录名、密码
            Restore2Class oRestore = new Restore2Class();
            oRestore.Database = this.txtDbName.Text.Trim();
            oRestore.Files = this.txtBackPath.Text.Trim();
            oRestore.Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
            try
            {
                oRestore.SQLRestore(oSqlServer);
                Response.Write("<script>alert('恢复成功!');window.location.href='restoredb.aspx'</script>");
            }
            catch
            {
                Response.Write("<script>alert('恢复失败!');window.location.href='restoredb.aspx'</script>");
            }
            finally
            {
                oRestore = null;
            }
       无论备份还是恢复 需要导入一个Interop.SQLDMO.dll的组件. 
       早上看到了<如何用SQLDMO在ASP.NET页面下实现数据库的备份与恢复 >写得非常棒.
  • 相关阅读:
    JQuery Mobile
    JQuery
    JQuery Mobile
    JQuery Mobile
    JQuery Mobile
    5G && 物联网
    Sass(Syntactically Awesome Stylesheets)——概述(待续)
    Sass(Syntactically Awesome Stylesheets)——使用React JS实现
    Yarn概述——FAST, RELIABLE, AND SECURE DEPENDENCY MANAGEMENT
    webpack——Modules && Hot Module Replacement
  • 原文地址:https://www.cnblogs.com/Caesar/p/1037780.html
Copyright © 2011-2022 走看看