In ASP. NET, how does one restore the SQL Server database backup? First, let's take a look at how SQL Server database backup is performed in ASP. NET.
The following is a reference segment for SQL Server database backup:
- 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();
- }
In ASP. NET, after backing up the SQL Server database, we will encounter database recovery operations. The following is the source code for restoring the SQL Server database backup:
- StringPath =This. FileUpload1.PostedFile. FileName;// Obtain the backup path and Database Name
- StringDbname =This. DropDownList1.SelectedValue;
- StringSqlStr1 ="Server = (local );
- Database = '"+This. DropDownList1.SelectedValue +"';
- Uid = sa; Pwd =";
- StringSqlStr2 ="Use master restore database"+ Dbname +"From disk = '"+ Path +"'";
- SqlConnection con =NewSqlConnection (SqlStr1 );
- Con. Open ();
- Try
- {
- SqlCommand com =NewSqlCommand (SqlStr2, con );
- Com. ExecuteNonQuery ();
- Response. Write ("");
- }
- Catch(Exception error)
- {
- Response. Write (error. Message );
- Response. Write ("");
- }
- Finally
- {
- Con. Close ();
- }
The SQL Server database backup and recovery in ASP. NET will be introduced here, and I hope it will help you.
- Detailed research on ASP. NET data verification technology
- Application of ASP. NET code separation in website construction
- Analysis on ASP. NET code optimization
- Analysis on the use of CustomValidator, an ASP. NET data verification control
- Analysis of embedded code block application in ASP. NET web pages