国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

ASP.NET下備份與還原數(shù)據(jù)庫代碼

來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 22:43:22
文檔

ASP.NET下備份與還原數(shù)據(jù)庫代碼

ASP.NET下備份與還原數(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 = S
推薦度:
導(dǎo)讀ASP.NET下備份與還原數(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 = S

核心技術(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>
<td><asp:DropDownList ID="DropDownList1" runat="server" Font-Size="9pt" Width="124px"></asp:DropDownList></td>
<td style="width: 100px; height: 21px"></td>
</tr>
<tr>
<td style="width: 100px"><span style="font-size: 9pt">操 作 數(shù) 據(jù) 庫</span></td>
<td style="width: 100px"><asp:FileUpload ID="FileUpload1" runat="server" Font-Size="9pt" Width="190px" /></td>
<td style="width: 100px">
</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 path = this.FileUpload1.PostedFile.FileName; //獲得備份路徑及數(shù)據(jù)庫名稱
string dbname = this.DropDownList1.SelectedValue;
string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "use master restore database " + dbname + " from disk='" + path + "'";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
try
{
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();
}
}
}

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

ASP.NET下備份與還原數(shù)據(jù)庫代碼

ASP.NET下備份與還原數(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 = S
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 亚洲欧洲综合在线 | 亚洲国产成人久久一区二区三区 | 国产成人h福利小视频在线观看 | 亚洲欧美日本在线观看 | 国产精品一区二区国产 | 欧美 日韩 国产 色 欧美 日韩 中文 | 国产手机在线αⅴ片无码观看 | 午夜精品久久久久久毛片 | 亚洲精品国产第七页在线 | 国产成人调教视频在线观看 | 国语对白91 | 九九久久亚洲综合久久久 | 亚洲 欧美 日韩在线 | 国产高清在线播放免费观看 | 国产高清在线精品一区二区三区 | 最刺激黄a大片免费观看 | 成人a毛片久久免费播放 | 欧美日韩国产在线播放 | 精品国产一区二区三区久久久狼 | 99精品视频在线观看免费 | 亚洲国产精品免费在线观看 | 欧美成人视屏 | 欧美色图第一页 | 国产日韩欧美综合在线 | 久久久久国产精品美女毛片 | 欧美videos极品另类 | 黄a免费 | 日韩精品在线看 | 欧美一级高清片欧美国产欧美 | 一级毛片免费的 | 国产l精品国产亚洲区在线观看 | 另类日韩| 成人国产精品一区二区网站 | 国产黄色免费看 | 国产在线91区精品 | 欧美日韩精品高清一区二区 | 一区二区三区高清 | 国产免费自拍 | 亚洲欧洲精品成人久久曰影片 | 欧美视频亚洲视频 | 久久久精品一区二区三区 |