欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2010年03月10日 23:01:40   作者:  
ASP.NET下備份還原數(shù)據(jù)庫的實現(xiàn)代碼,需要的朋友可以參考下。
核心技術(shù):
復(fù)制代碼 代碼如下:

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.前臺
復(fù)制代碼 代碼如下:

<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.后臺
復(fù)制代碼 代碼如下:

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ù):
復(fù)制代碼 代碼如下:

string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "use master restore database " + dbname + " from disk='" + path + "'";

1.前臺
復(fù)制代碼 代碼如下:

<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.后臺
復(fù)制代碼 代碼如下:

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();
}
}
}

相關(guān)文章

  • Json返回時間的格式中出現(xiàn)亂碼問題的兩種解決方案

    Json返回時間的格式中出現(xiàn)亂碼問題的兩種解決方案

    使用Json返回數(shù)據(jù)的時候時間的格式一般都會變了,變成我們不認識的一些字符,那么當(dāng)我們遇到這些問題的時候我們該怎么解決呢,今天我就來小說一下這個的解決方法
    2013-10-10
  • .NET Core類庫System.Reflection.DispatchProxy實現(xiàn)簡易Aop的方法

    .NET Core類庫System.Reflection.DispatchProxy實現(xiàn)簡易Aop的方法

    這篇文章主要給大家介紹了關(guān)于.NET Core類庫System.Reflection.DispatchProxy實現(xiàn)簡易Aop的相關(guān)資料,文中通過示例代碼結(jié)束的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • asp.net iis 無法顯示網(wǎng)頁的解決方法分析

    asp.net iis 無法顯示網(wǎng)頁的解決方法分析

    使用過IIS的朋友都可能遇到過這樣的情況:即使您按照教科書的步驟做好各步設(shè)置以后,仍會出現(xiàn)“無法顯示網(wǎng)頁”的現(xiàn)象。
    2010-06-06
  • 淺談對Jquery+JSON+WebService的使用小結(jié)

    淺談對Jquery+JSON+WebService的使用小結(jié)

    本篇文章介紹了對Jquery+JSON+WebService的使用小結(jié)。需要的朋友參考下
    2013-04-04
  • Discuz!NT 3與asp.net 整合的實例教程

    Discuz!NT 3與asp.net 整合的實例教程

    本次整合只針對NETSNS中的代碼做了少許修改,完成了基本的和論壇同步注冊,登陸和注銷,信息獲取,信息修改。為的是給各位Discuz!NT API愛好者做一個簡單的API事例,供大家參考。
    2009-11-11
  • asp.net 2個日期之間的整月數(shù)的算法

    asp.net 2個日期之間的整月數(shù)的算法

    我是說兩個日期之間間隔整月,比如2008-11-5 和 2009-4-3之間的整月,結(jié)果是12,1,2,3這四個月
    2009-06-06
  • Visual?Studio快捷鍵匯總

    Visual?Studio快捷鍵匯總

    這篇文章介紹了Visual?Studio的常用快捷鍵,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • ASP.NET MVC5網(wǎng)站開發(fā)添加文章(八)

    ASP.NET MVC5網(wǎng)站開發(fā)添加文章(八)

    小編整理的ASP.NET MVC5網(wǎng)站開發(fā)是一系列的文章體系,大家要一篇篇的仔細閱讀,今天這篇文章主要介紹了ASP.NET MVC5網(wǎng)站開發(fā)添加文章,需要的朋友可以參考下
    2015-09-09
  • c# 在WebBrowser中用SendMessage模擬鼠標(biāo)點擊

    c# 在WebBrowser中用SendMessage模擬鼠標(biāo)點擊

    想在WebBrowser控件里面模擬鼠標(biāo)點擊,在百度上找了半天,怎么也找不到,還是google強大,在一個國外網(wǎng)站上找到的,代碼比較清楚了,不做說明。
    2010-02-02
  • .net core中Quartz的使用方法

    .net core中Quartz的使用方法

    這篇文章主要介紹了.net core中Quartz的使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03

最新評論