zoukankan      html  css  js  c++  java
  • 在ASP.NET中备份恢复Sql Server数据库

    向大家介绍如何使用 ASP.NET 备份恢复 Sql Server 数据库,大家可以做个参考,也希望对大家有所帮助。  备份SqlServer数据库:
    以下是引用片段:
      string SqlStr1 = "Server=(local);database=’" + this.DropDownList1.SelectedValue + "’;Uid=sa;Pwd="; 
      string SqlStr2 = "backup database " + this.DropDownList1.SelectedValue + " to disk=’" + this.TextBox1.Text.Trim() + ".bak’"; 
      SqlConnection con = new SqlConnection(SqlStr1); 
      con.Open(); 
      try 
      { 
      if (File.Exists(this.TextBox1.Text.Trim())) 
      { 
      Response.Write(" "); 
      return; 
      } 
      SqlCommand com = new SqlCommand(SqlStr2, con); 
      com.ExecuteNonQuery(); 
      Response.Write(" "); 
      } 
      catch (Exception error) 
      { 
      Response.Write(error.Message); 
      Response.Write(" "); 
      } 
      finally 
      { 
      con.Close(); 
      } 

      还原SqlServer数据库:
    以下是引用片段:
      string path = this.FileUpload1.PostedFile.FileName; //获得备份路径及数据库名称 
      string dbname = this.DropDownList1.SelectedValue; 
      string SqlStr1 = "Server=(local);database=’" + this.DropDownList1.SelectedValue + "’;Uid=sa;Pwd="; 
      string SqlStr2 = "use master restore database " + dbname + " from disk=’" + path + "’"; 
      SqlConnection con = new SqlConnection(SqlStr1); 
      con.Open(); 
      try 
      { 
      SqlCommand com = new SqlCommand(SqlStr2, con); 
      com.ExecuteNonQuery(); 
      Response.Write(" "); 
      } 
      catch (Exception error) 
      { 
      Response.Write(error.Message); 
      Response.Write(" "); 
      } 
      finally 
      { 
      con.Close(); 
      } 

  • 相关阅读:
    angular运行报错“Cannot find module 'ng2-translate'.”
    切换分支
    下载angular项目报错[ERROR] ionic-app-scripts has unexpectedly closed (exit code 1).
    通过原生SQL判断数据是否存在
    多图合并一张长图脚本
    科大讯飞--新冠肺炎检测赛道第八分享
    Mysql定时任务
    Mysql导出数据结构 or 数据
    G6Editor 边的参数配置
    百度坐标转腾讯坐标
  • 原文地址:https://www.cnblogs.com/88223100/p/1016208.html
Copyright © 2011-2022 走看看