掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
ASP.NET中SQL Server數(shù)據(jù)庫(kù)備份恢復(fù)的操作是如何的呢?首先我們來(lái)看看在ASP.NET中是怎么進(jìn)行SQL Server數(shù)據(jù)庫(kù)備份的。

以下是進(jìn)行SQL Server數(shù)據(jù)庫(kù)備份引用片段:
- 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(" ");
- return;
- }
- SqlCommand com = new SqlCommand(SqlStr2, con);
- com.ExecuteNonQuery();
- Response.Write(" ");
- }
- catch (Exception error)
- {
- Response.Write(error.Message);
- Response.Write(" ");
- }
- finally
- {
- con.Close();
- }
那么在ASP.NET中SQL Server數(shù)據(jù)庫(kù)備份之后我們會(huì)遇到恢復(fù)數(shù)據(jù)庫(kù)的操作,下面呢就是SQL Server數(shù)據(jù)庫(kù)備份恢復(fù)的源碼:
- string path = this.FileUpload1.PostedFile.FileName; //獲得備份路徑及數(shù)據(jù)庫(kù)名稱
- 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(" ");
- }
- catch (Exception error)
- {
- Response.Write(error.Message);
- Response.Write(" ");
- }
- finally
- {
- con.Close();
- }
ASP.NET中SQL Server數(shù)據(jù)庫(kù)備份恢復(fù)的相關(guān)內(nèi)容就向你介紹到這里,希望對(duì)你有所幫助。

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流