国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET備份恢復SqlServer數據庫_.Net教程

2024-07-10 12:50:32
字體:
來源:轉載
供稿:網友

推薦:asp.net編程中實現 MD5 加密
現在制作的web系統需要用到加密 依舊選擇md5吧(其實我也就用過md5^_^) 找到了兩種實現 方案一: /**//// /// 用md5加密 ///

備份SqlServer數據庫
核心技術:

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">操 作 數 據 庫</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="備份數據庫" /></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('備份數據成功!');location='Default.aspx'</script>");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write("<script language=javascript>alert('備份數據失敗!')</script>");
}
finally
{
con.Close();
}
}
}

還原SqlServer
核心技術:

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">操 作 數 據 庫</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">操 作 數 據 庫</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="還原數據庫" /></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; //獲得備份路徑及數據庫名稱
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('還原數據成功!');location='Default.aspx'</script>");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write("<script language=javascript>alert('還原數據失敗!')</script>");
}
finally
{
con.Close();
}
}
}

分享:ASP.NET常用的三十三種實用代碼
1. 打開新的窗口并傳送參數: 傳送參數: response.write("<script>window.open(’*.aspx?id=" this.DropDownList1.SelectIndex &

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彝良县| 二连浩特市| 淮安市| 灌云县| 宽城| 德兴市| 琼结县| 南京市| 平山县| 诸暨市| 陵川县| 子长县| 巴塘县| 六安市| 松原市| 龙州县| 吉林省| 洱源县| 宿松县| 榆林市| 阳原县| 盐源县| 宜川县| 宁南县| 武汉市| 西充县| 从化市| 扎囊县| 泌阳县| 安龙县| 龙山县| 泗洪县| 夏津县| 信阳市| 内江市| 武安市| 沈丘县| 安福县| 稻城县| 宜州市| 南岸区|