zoukankan      html  css  js  c++  java
  • asp.net 在线备份SQL数据库

    BackUpDB.aspx

    View Code
    1 <div>
    2
    3 备份数据库:<asp:DropDownList ID="db" runat="server">
    4 </asp:DropDownList>
    5 <br />
    6 <br />
    7
    8 </div>
    9 <div>
    10
    11 备份名称和位置:<asp:TextBox ID="positions" runat="server"></asp:TextBox>
    12 <br />
    13 <asp:Button ID="btBK" runat="server" onclick="btBK_Click" Text="开始备份" />
    14 <br />
    15
    16 </div>

    BackUpDB.aspx.cs

    View Code
    1 protected void Page_Load(object sender, EventArgs e)
    2 {
    3 if (!Page.IsPostBack)
    4 {
    5 BindDB();
    6 }
    7 }
    8
    9 private void BindDB()
    10 {
    11 DataSet ds = SQLHelper.Query ("Exec sp_helpdb");
    12 db.DataSource = ds;
    13 db.DataTextField = "name";
    14 db.DataBind();
    15 }
    16
    17 protected void btBK_Click(object sender, EventArgs e)
    18 {
    19 string SQL_STR = "backup database " + db.SelectedValue + " to disk='" + positions.Text.Trim() + ".bak'";
    20 try
    21 {
    22 if (File.Exists(positions.Text.Trim()))
    23 {
    24 Response.Write("<script>alert('此文件己存在,请重新输入!');location='BackUpDB.aspx'</script>");
    25 return;
    26 }
    27 SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStr, CommandType.Text, SQL_STR, null);
    28 Response.Write("<script>alert('备份数据成功!');location='BackUpDB.aspx'</script>");
    29 }
    30 catch (Exception ee)
    31 {
    32 Response.Write(ee.Message);
    33 Response.Write("<script>alert('备份数据库失败!')</script>");
    34 }
    35
    36 }
    作者:Jack Qin 互联网新鲜事:http://www.nosqlcn.com
  • 相关阅读:
    brew
    hbase
    YARN常见问题以及解决方案
    mybatis中foreach collection三种用法
    mysql按分隔符输出多行
    mysql DATETIME
    iis 之给网站添加MIME映射
    VS2019专业版和企业版激活密钥
    ViewData对于从后台传list到前台的使用
    找出每组数据中不同distinct
  • 原文地址:https://www.cnblogs.com/JackQ/p/2099195.html
Copyright © 2011-2022 走看看