"> 后台: using System; using System.Collections.Generic; using System.Linq; using Syste">
当前位置:Gxlcms > mysql > ASP.NET恢复备份Sqlserver

ASP.NET恢复备份Sqlserver

时间:2021-07-01 10:21:17 帮助过:19人阅读

前台代码:

  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SqlDbMgmt.x.cs" Inherits="SysSourceMgmt.SqlDbMgmt" %>

  ">

  

  

  

  

  

  

  

  

   后台:

  using System;

  using System.Collections.Generic;

  using System.Linq;

  using System.Web;

  using System.Web.UI;

  using System.Web.UI.WebControls;

  using System.Data.SqlClient;

  using System.IO;

  using System.Data;

  using System.Diagnostics;

  namespace SysSourceMgmt

  {

  public partial class SqlDbMgmt : System.Web.UI.Page

  {

  protected void Page_Load(object sender, EventArgs e)

  {

  if (!IsPostBack)

  {

  try

  {

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

  SqlStr1 = "Server=(local);DataBase=master;Uid=sa;Pwd=";

  SqlStr2 = "Exec sp_helpdb";

  con = new SqlConnection(SqlStr1);

  con.Open();

  com = new SqlCommand(SqlStr2, con);

  dr = com.ExecuteReader();

  this.DropDownList1.DataSource = dr;

  this.DropDownList1.DataTextField = "name";

  this.DropDownList1.DataBind();

  dr.Close();

  con.Close();

  }

  catch (Exception)

  {

  }

  }

  }

  protected void Button1_Click(object sender, EventArgs e)

  {

  string dbName = string.Empty;

  if (DropDownList1.Items.Count != 0)

  {

  dbName = DropDownList1.SelectedValue.Trim();

  }

  else

  {

  dbName = txtDbName.Text.Trim();

  }

  string SqlStr1 = "Data Source=.\sqlexpress;Initial Catalog='" + dbName + "';Integrated Security=True";

  string SqlStr2 = "backup database " + dbName + " to disk='" + this.TextBox1.Text.Trim() + ".bak'";

  SqlConnection con = new SqlConnection(SqlStr1);

  con.Open();

  try

  {

  if (File.Exists(this.TextBox1.Text.Trim()))

  {

  Response.Write("