ASP.NET中SQL Server数据库备份恢复浅析
创始人
2024-04-25 05:11:03
0

ASP.NET中SQL Server数据库备份恢复的操作是如何的呢?首先我们来看看在ASP.NET中是怎么进行SQL Server数据库备份的。

以下是进行SQL Server数据库备份引用片段:

  1.   string SqlStr1 = "Server=(local);
  2. database='" + this.DropDownList1.SelectedValue + "';
  3. Uid=sa;Pwd=";   
  4.   string SqlStr2 = "backup database " + 
  5. this.DropDownList1.SelectedValue + " to disk='" + 
  6. this.TextBox1.Text.Trim() + ".bak'";   
  7.   SqlConnection con = new SqlConnection(SqlStr1);   
  8.   con.Open();   
  9.   try   
  10.   {   
  11.   if (File.Exists(this.TextBox1.Text.Trim()))   
  12.   {   
  13.   Response.Write(" ");   
  14.   return;   
  15.   }   
  16.   SqlCommand com = new SqlCommand(SqlStr2, con);   
  17.   com.ExecuteNonQuery();   
  18.   Response.Write(" ");   
  19.   }   
  20.   catch (Exception error)   
  21.   {   
  22.   Response.Write(error.Message);   
  23.   Response.Write(" ");   
  24.   }   
  25.   finally   
  26.   {   
  27.   con.Close();   
  28.   }  

那么在ASP.NET中SQL Server数据库备份之后我们会遇到恢复数据库的操作,下面呢就是SQL Server数据库备份恢复的源码:

  1.   string path = this.FileUpload1.PostedFile.FileName; //获得备份路径及数据库名称   
  2.   string dbname = this.DropDownList1.SelectedValue;   
  3.   string SqlStr1 = "Server=(local);
  4. database='" + this.DropDownList1.SelectedValue + "';
  5. Uid=sa;Pwd=";   
  6.   string SqlStr2 = "use master restore database " + dbname + " from disk='" + path + "'";   
  7.   SqlConnection con = new SqlConnection(SqlStr1);   
  8.   con.Open();   
  9.   try   
  10.   {   
  11.   SqlCommand com = new SqlCommand(SqlStr2, con);   
  12.   com.ExecuteNonQuery();   
  13.   Response.Write(" ");   
  14.   }   
  15.   catch (Exception error)   
  16.   {   
  17.   Response.Write(error.Message);   
  18.   Response.Write(" ");   
  19.   }   
  20.   finally   
  21.   {   
  22.   con.Close();   
  23.   }  

ASP.NET中SQL Server数据库备份恢复的相关内容就向你介绍到这里,希望对你有所帮助。

【编辑推荐】

  1. ASP.NET数据验证技术研究详解
  2. ASP.NET代码分离之网站建设应用浅析
  3. ASP.NET代码优化浅析
  4. ASP.NET数据验证控件CustomValidator的使用浅析
  5. ASP.NET网页中的嵌入式代码块应用浅析

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...