• 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
  • 相关阅读:
    MyBatis总结(一)
    MyBatis简介
    数据持久化与ORM
    主流框架介绍
    JSP数据交互(一)
    tomcat端口被占用
    动态网页开发基础
    jQuery内容
    正则表达式
    初始Mybatis
  • 原文地址:https://www.cnblogs.com/JackQ/p/2099195.html
Copyright © 2020-2023  润新知