最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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
核心技術:
復制代碼 代碼如下:

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

相關文章

  • 詳解使用DotNet CLI創(chuàng)建自定義的WPF項目模板

    詳解使用DotNet CLI創(chuàng)建自定義的WPF項目模板

    這篇文章主要介紹了詳解使用DotNet CLI創(chuàng)建自定義的WPF項目模板,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • 為HttpClient添加默認請求報頭的四種解決方案

    為HttpClient添加默認請求報頭的四種解決方案

    這篇文章主要給大家介紹了關于為HttpClient添加默認請求報頭的四種解決方案,文中通過示例代碼介紹的非常詳細,對大家學習或者使用HttpClient具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-09-09
  • MVC+EasyUI+三層架構簡單權限管理系統(tǒng)

    MVC+EasyUI+三層架構簡單權限管理系統(tǒng)

    這篇文章主要為大家詳細介紹了MVC+EasyUI+三層架構簡單權限管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • 正確使用dotnet-*工具的方法

    正確使用dotnet-*工具的方法

    這篇文章介紹了正確使用dotnet-*工具的方法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-12-12
  • asp.net?core集成ElasticSearch實現(xiàn)全文檢索功能

    asp.net?core集成ElasticSearch實現(xiàn)全文檢索功能

    索引是Elasticsearch中用于存儲文檔的容器,你可以使用Elasticsearch的REST?API、官方客戶端庫(如NEST)或Kibana等工具來創(chuàng)建和管理索引,本文給大家介紹asp.net?core集成ElasticSearch實現(xiàn)全文檢索功能,感興趣的朋友一起看看吧
    2024-08-08
  • ASP.NET配合jQuery解決跨域調(diào)用的問題

    ASP.NET配合jQuery解決跨域調(diào)用的問題

    這篇文章主要介紹了ASP.NET配合jQuery解決跨域調(diào)用的問題,簡單實用,需要的朋友可以參考下。
    2016-06-06
  • VS2013安裝提示必須安裝ie10的解決辦法

    VS2013安裝提示必須安裝ie10的解決辦法

    這篇文章主要為大家詳細介紹了VS2013安裝提示必須安裝ie10的解決辦法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • .NET Orm性能測試分析

    .NET Orm性能測試分析

    本篇文章給大家分享了.NET Orm性能測試的結(jié)果分析內(nèi)容,對此有需要的朋友可以參考學習下。
    2018-05-05
  • ASP.NET Core 3.0遷移的完美避坑指南

    ASP.NET Core 3.0遷移的完美避坑指南

    這篇文章主要給大家介紹了關于ASP.NET Core 3.0遷移的完美避坑指南,文中通過示例代碼介紹的非常詳細,對大家學習或者使用ASP.NET Core 3.0具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-09-09
  • .NET?Core類庫項目中讀取appsettings.json配置的方法

    .NET?Core類庫項目中讀取appsettings.json配置的方法

    ASP.NET?Core是一個全新的Web開發(fā)平臺,微軟在它上面構建了MVC、SingalR、GRPC、Orleans這樣廣泛使用的Web框架,今天通過本文給大家詳細介紹下.NET?Core讀取appsettings.json配置的方法,感興趣的朋友一起看看吧
    2022-03-03

最新評論

五家渠市| 双牌县| 巢湖市| 砀山县| 阿克| 台北县| 镇沅| 渑池县| 嵊州市| 漾濞| 麻江县| 龙岩市| 临西县| 马尔康县| 张家界市| 阜宁县| 永年县| 宜良县| 宜丰县| 富阳市| 汉阴县| 阿拉善左旗| 兴文县| 张家口市| 墨竹工卡县| 栖霞市| 青河县| 合肥市| 贵州省| 措勤县| 左权县| 禹城市| 仁寿县| 右玉县| 乌兰浩特市| 古田县| 桃江县| 华坪县| 新宾| 图木舒克市| 成安县|