//数据库备份
     protected void btnBackup_Click(object sender, EventArgs e)
    {
        string bakname = "cc";
        string sql = "backup database tt to disk = '" + Server.MapPath("").ToString() + "\\"
        + bakname //备份文件名
        + ".bak'";

        SqlConnection scon = new SqlConnection("server=.;uid=sa;pwd=sa;database=tt");
        scon.Open();
        SqlCommand sc = new SqlCommand(sql, scon);
        sc.ExecuteNonQuery();

    }

//数据库的还原


    protected void Button1_Click(object sender, EventArgs e)
    {
        //string path = this.FileUpload1.PostedFile.FileName; //获得备份路径及数据库名称
        string path = "D:/1.BAK";
        //string dbname = this.DropDownList1.SelectedValue;
        string SqlStr1 = "Server=.;database=WebZone;Uid=sa;Pwd=sa";
        string SqlStr2 = "use master restore database WebZone from disk='" + path + "'";
        SqlConnection con = new SqlConnection(SqlStr1);
        con.Open();
        try
        {
            SqlCommand com = new SqlCommand(SqlStr2, con);
            com.ExecuteNonQuery();
            Response.Write("<script language=javascript>alert('还原数据成功!');</script>");
        }
        catch (Exception error)
        {
            Response.Write(error.Message);Response.Write("<script language=javascript>alert('还原数据失败!');</script>");
       
        }
        finally
        {
            con.Close();
        }
    }

相关文章:

  • 2021-08-31
  • 2022-02-14
  • 2021-09-02
  • 2021-09-02
  • 2021-10-28
  • 2021-05-24
猜你喜欢
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-01-09
相关资源
相似解决方案