日期:2014-05-18 浏览次数:20451 次
string myStr = System.Configuration.ConfigurationManager.AppSettings["98lunwen"]; protected void btn_backup_Click(object sender, EventArgs e) { SqlConnection myConn = new SqlConnection(myStr); string SqlStr1 = "Exec sp_helpdb"; myConn.Open(); SqlCommand com = new SqlCommand(SqlStr1, myConn); SqlDataReader dr = com.ExecuteReader(); string SqlStr2 = "backup database lunwena to disk='~/Admin/BAK/lunwena_B.bak'"; try { SqlCommand com1 = new SqlCommand(SqlStr2, myConn); com1.ExecuteNonQuery(); Response.Write("<script language=javascript>alert('备份数据成功!')</script>"); } catch (Exception error) { Response.Write(error.Message); Response.Write("<script language=javascript>alert('备份数据失败!')</script>"); } finally { myConn.Close(); } Response.Redirect("Web_Database.aspx"); } protected void btn_return_Click(object sender, EventArgs e) { SqlConnection myConn = new SqlConnection(myStr); string SqlStr1 = "Exec sp_helpdb"; myConn.Open(); SqlCommand com = new SqlCommand(SqlStr1, myConn); SqlDataReader dr = com.ExecuteReader(); string SqlStr2 = "use master restore database lunwena_B from disk='~/Admin/BAK/lunwena_B.bak'"; try { SqlCommand com1 = new SqlCommand(SqlStr2, myConn); com1.ExecuteNonQuery(); Response.Write("<script language=javascript>alert('还原数据成功!')</script>"); } catch (Exception error) { Response.Write(error.Message); Response.Write("<script language=javascript>alert('还原数据失败!')</script>"); } finally { myConn.Close(); } Response.Redirect("Web_Database.aspx"); }