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
  • 相关阅读:
    通过strace 监控 fdatasync
    RAID 2.0
    AHCI vs NVMe
    NVMe 图解
    详解linux运维工程师入门级必备技能
    条带深度 队列深度 NCQ IOPS
    NVMe 与 AHCI
    IO负载高的来源定位 IO系列
    磁盘性能指标--IOPS 理论
    java程序员从笨鸟到菜鸟系列
  • 原文地址:https://www.cnblogs.com/JackQ/p/2099195.html
Copyright © 2011-2022 走看看