①创建Web应用程序窗体
在Web窗体(DataBase2.aspx)上放置一个按钮: <asp:Button ID="BackUpBtn" runat="server" Text=" 备份数据库 " OnClick="BackUpBtn_Click" />
再添加一个Label控件: <asp:Label ID="MsgLabel" runat="server"></asp:Label>
②添加引用的空间名称
using System; using System.IO;
③备份SQL数据库的代码
//备份数据库 protected void BackUpBtn_Click(object sender, EventArgs e) { string DbPath1, DbPath2, DbName4DbPath2;
DbName4DbPath2 = DateTime.Now.ToString().Replace(":","."); DbPath1 = Server.MapPath("../App_Data/DataBase.mdb"); DbPath2 = Server.MapPath("../App_Data/" + DbName4DbPath2 + ".mdb");
try { File.Copy(DbPath1, DbPath2, true);
MsgLabel.Text = "数据库备份成功到" + DbName4DbPath2 + ".mdb!"; } catch { MsgLabel.Text = "数据库备份失败,请重试!"; MsgLabel.CssClass = "redColor"; } }
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18