asp.net在后台怎么对Sql Server 数据库备份

来源:百度知道 编辑:UC知道 时间:2024/06/15 21:44:39
现在我要在后台做一个按钮,在点击后就要把指定的数据库备份到自己要备份的地方,还没有思路,请高手指教
也就是在后台一个傻瓜式的对SQL数据库的备份
得到当前SQL数据库里面的所有database用什么办法 ,还是可以用SQL语句得到?

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string path=@"c:\Test.bak";
string backupstr="backup database Test to disk='"+path+"';";
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand(backupstr, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
this.Label1.Text = "备