亚洲AV无码乱码在线观看不卡|最新大伊香蕉精品视频在线|亚洲不卡av一区二区|国产美女无遮挡免费

登錄論壇 | 注冊會員 設(shè)為首頁 | 收藏本站
當前位置 : 首頁>軟件學(xué)院>程序開發(fā)>ASP.NET>正文
 
ASP.NET備份恢復(fù)SqlServer數(shù)據(jù)庫

http://www.yibo1263.com 2008-5-4 19:25:08  來源:本站  編輯:阿拉格調(diào)
 

備份SqlServer數(shù)據(jù)庫
核心技術(shù):
using System.Data.SqlClient;
using System.IO;
string SqlStr1 = "Server=(local);DataBase=master;Uid=sa;Pwd=";
string SqlStr2 = "Exec sp_helpdb";
string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "backup database " + this.DropDownList1.SelectedValue + " to disk='" + this.TextBox1.Text.Trim() + ".bak'";

1.前臺

<table>
<tr>
<td style="width: 100px"><span style="font-size: 9pt">操 作 數(shù) 據(jù) 庫</span></td>
<td><asp:DropDownList ID="DropDownList1" runat="server" Font-Size="9pt" Width="124px"></asp:DropDownList></td>
<td style="width: 100px"></td>
</tr>
<tr>
<td style="width: 100px"><span style="font-size: 9pt">備份名稱和位置</span></td>
<td style="width: 100px"><asp:TextBox ID="TextBox1" runat="server" Font-Size="9pt" Width="117px"></asp:TextBox></td>
<td style="width: 100px"><span style="font-size: 9pt; color: #ff3300">(如D:\beifen)</span></td>
</tr>
<tr>
<td colspan="3"><asp:Button ID="Button1" runat="server" Font-Size="9pt" OnClick="Button1_Click" Text="備份數(shù)據(jù)庫" /></td>
</tr>
</table>

2.后臺

using System.Data.SqlClient;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string SqlStr1 = "Server=(local);DataBase=master;Uid=sa;Pwd=";
string SqlStr2 = "Exec sp_helpdb";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
SqlCommand com = new SqlCommand(SqlStr2, con);
SqlDataReader dr = com.ExecuteReader();
this.DropDownList1.DataSource = dr;
this.DropDownList1.DataTextField = "name";
this.DropDownList1.DataBind();
dr.Close();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "backup database " + this.DropDownList1.SelectedValue + " to disk='" + this.TextBox1.Text.Trim() + ".bak'";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
try
{
if (File.Exists(this.TextBox1.Text.Trim()))
{
Response.Write("<script language=javascript>alert('此文件已存在,請從新輸入!');location='Default.aspx'</script>");
return;
}
SqlCommand com = new SqlCommand(SqlStr2, con);
com.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('備份數(shù)據(jù)成功!');location='Default.aspx'</script>");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write("<script language=javascript>alert('備份數(shù)據(jù)失!')</script>");
}
finally
{
con.Close();
}
}
}



還原SqlServer
核心技術(shù):
string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "use master restore database " + dbname + " from disk='" + path + "'";

1.前臺
<table>
<tr>
<td style="width: 100px; height: 21px"><span style="font-size: 9pt">操 作 數(shù) 據(jù) 庫</span></td>

本新聞共2頁,當前在第1頁  1  2  

 
收藏】【打印】【進入論壇
  相關(guān)文章:

·淺析五大ASP.NET數(shù)據(jù)控件
·Discuz!NT 3.1 為ASP.net社區(qū)提速 
·淺析五大ASP.NET數(shù)據(jù)控件
·ASP.NET全局異常處理的方法
·asp.net實現(xiàn)驗證碼
·ASP.NET中在線用戶統(tǒng)計
·用ASP.NET加密口令
·在ASP.NET中使用Microsoft Word文檔
·Asp.net+Xml開發(fā)網(wǎng)絡(luò)硬盤 
·用ASP.NET構(gòu)建簡單的Web Form 
·ASP.Net中自定義Http處理及應(yīng)用之HttpModul

 
 
 
 
最新文章

中關(guān)村艷照門女主角詳記錄高清組圖 
大連護士門大尺度艷照高清組圖
iPhone女孩微博爆紅 最寶貴東西換iPhon
反恐精英之父內(nèi)維爾:改變電腦游戲銷售
團購網(wǎng)站黎明之前:中國市場慘烈廝殺不
團購鼻祖Groupon中國揭秘:快與慢的商業(yè)
Spil Games發(fā)布新的品牌形象
1800配置一臺主機 不要顯示器
聯(lián)想V360筆記本模特寫真
愛國者第四代移動硬盤將面市、低電壓保

 
推薦文章
1
2
3
4
5
6
7
8
9
10
iPhone女孩微博爆紅 最寶貴東西換
大連護士門大尺度艷照高清組圖
中關(guān)村艷照門女主角詳記錄高清組
蘋果員工中毒門
宮如敏不雅照瘋傳 看張馨予韓一菲
深耕市場 永續(xù)經(jīng)營——專訪百腦匯
優(yōu)派專業(yè)電子書 讓您回家旅途多姿
揭曉百萬大獎三星bada魅力綻放中
大明龍權(quán)“江湖英雄會”全國PK大
永恒之塔校園達人挑戰(zhàn)賽完美落幕
八卦圖解 More>>
iPhone女孩微博爆紅 最寶貴東西換 大連護士門大尺度艷照高清組圖
中關(guān)村艷照門女主角詳記錄高清組 宮如敏不雅照瘋傳 看張馨予韓一菲