Backup1/houtai/backup.aspx.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace 淮安协和门诊.houtai
{
public partial class backup : System.Web.UI.Page
{
static string connstr = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];//定义静态链接数据库参数
SqlConnection Conn = new SqlConnection(connstr);//定义连接数据库连接对象conn
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~//backup") + "//" + "sql.bak";
string sql = "use master;backup database xhmz to disk ='" + path + "'";
SqlCommand cmd = new SqlCommand(sql, Conn);//创建cmd对象,执行sql操作
Conn.Open();//打开数据库连接
cmd.ExecuteNonQuery();//执行cmd的执行函数
Response.ContentType = "application/ms-download";
System.IO.FileInfo file = new System.IO.FileInfo(path);//upload文件夹中存放了上传的资源文件,这里为资源文件的路径
Response.Clear();
Response.AddHeader("Content-Type", "application/octet-stream");
Response.Charset = "utf-8";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.Flush();
Response.Clear();
Response.End();
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。