• 数据库的备份与恢复


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

    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页面下实现数据库的备份与恢复 >写得非常棒.
  • 相关阅读:
    【总】IdentityServer4 32篇汇总
    ASP.NET Core的身份认证框架IdentityServer4(3)-术语的解释
    ASP.NET Core身份认证服务框架IdentityServer4(2)-整体介绍
    dentityServer4(1)- 特性一览
    Identity和IdentityServer的区别及联系
    if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?
    ASP.NET Core 认证与授权[1]:初识认证
    如何优化Python占用的内存,面试必学
    Python3的这些新特性很方便,新手必学
    Python常见面试题,80%的人不会
  • 原文地址:https://www.cnblogs.com/Caesar/p/1037780.html
Copyright © 2020-2023  润新知