ASP.NET中SQL Server數(shù)據(jù)庫備份恢復(fù)淺析
作者:佚名
SQL Server數(shù)據(jù)庫備份恢復(fù)對于編程人員來說是經(jīng)常碰到的問題,那么如何處理呢?我們將在本文中向你介紹處理SQL Server數(shù)據(jù)庫備份恢復(fù)的程序源碼。
ASP.NET中SQL Server數(shù)據(jù)庫備份恢復(fù)的操作是如何的呢?首先我們來看看在ASP.NET中是怎么進(jìn)行SQL Server數(shù)據(jù)庫備份的。
以下是進(jìn)行SQL Server數(shù)據(jù)庫備份引用片段:
- 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ù)庫備份之后我們會遇到恢復(fù)數(shù)據(jù)庫的操作,下面呢就是SQL Server數(shù)據(jù)庫備份恢復(fù)的源碼:
- 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(" ");
- }
- catch (Exception error)
- {
- Response.Write(error.Message);
- Response.Write(" ");
- }
- finally
- {
- con.Close();
- }
ASP.NET中SQL Server數(shù)據(jù)庫備份恢復(fù)的相關(guān)內(nèi)容就向你介紹到這里,希望對你有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡
來源:
網(wǎng)頁設(shè)計(jì)