| 订阅 | 在线投稿
分享
 
 
 

ASP.NET中备份SQL Server数据库的方法

2008-07-12 07:37:34 编辑來源:互联网 国际版 评论
 
 
本文为【ASP.NET中备份SQL Server数据库的方法】的汉字拼音对照版显示拼音
  qianyan:womenzaikaifawangzhanshi,zaiguanlihoutai,guanliyuantongchangyaodingqiduishujukujinxingbeifen(dangranyekeyirangsqlserverfuwuqidingqizidongbeifen,danwocichujiangdeshiasp.netzhongdebeifen),beifendedaimahenjiandan:

  xiamianshiwozuoyigewangzhanhoutaishizai"beifen"anniuxiaxiedeyigeshijian:

  protected void Button1_Click(object sender, EventArgs e)

  ...{

  string newname = "WebJake" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString()+".bak";

  SqlConnection cn = DB.createCon();

  string nepath=Server.MapPath("../../DataBack/")+newname;

  string sql = "BACKUP DATABASE WebJake to DISK ='"+nepath+"'";

  SqlCommand cmd = new SqlCommand(sql,cn);

  try

  ...{

  cn.Open();

  cmd.ExecuteNonQuery();

  HyperLink1.Text = "yichenggongbeifendaofuwuqilujing" + nepath+" qingdianjixiazaidaobendi";

  HyperLink1.NavigateUrl = "../../DataBack/"+newname;

  HyperLink1.Visible = true;

  }

  catch (Exception ex)

  ...{

  string exm = ex.Message;

  Label1.Text = "beifenshujukuchucuogaiwenjiankenengbucunzai";

  Label1.Visible = true;

  }

  finally

  ...{

  cmd.Dispose();

  cn.Close();

  cn.Dispose();

  }

  dangranzuiguanjiandehuanshizheju:

  BACKUP DATABASE WebJake to DISK ='ninyaobaocundelujing'原文
 
 
前言:我们在开发网站时,在管理后台,管理员通常要定期对数据库进行备份(当然也可以让sqlserver服务器定期自动备份,但我此处讲的是asp.net中的备份),备份的代码很简单: 下面是我做一个网站后台时在"备份"按扭下写的一个事件: protected void Button1_Click(object sender, EventArgs e) ...{ string newname = "WebJake" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString()+".bak"; SqlConnection cn = DB.createCon(); string nepath=Server.MapPath("../../DataBack/")+newname; string sql = "BACKUP DATABASE WebJake to DISK ='"+nepath+"'"; SqlCommand cmd = new SqlCommand(sql,cn); try ...{ cn.Open(); cmd.ExecuteNonQuery(); HyperLink1.Text = "已成功备份到服务器路径:" + nepath+" 请点击下载到本地!"; HyperLink1.NavigateUrl = "../../DataBack/"+newname; HyperLink1.Visible = true; } catch (Exception ex) ...{ string exm = ex.Message; Label1.Text = "备份数据库出错,该文件可能不存在!"; Label1.Visible = true; } finally ...{ cmd.Dispose(); cn.Close(); cn.Dispose(); } 当然最关键的还是这句: BACKUP DATABASE WebJake to DISK ='您要保存的路径'
󰈣󰈤
 
 
>>返回首页<<
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 
 热帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
©2005- 王朝网络 版权所有