这是我附的源代码,实现的备份和恢复很简单,大家可以自己在补充....(有BUG的话,欢迎指教)
这是WEB后台程序
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 = "备份成功!";
}
catch
{
this.Label1.Text = "备份失败!";
}
finally
{
con.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string path = @"c:\Test.bak";
string restore="restore database Test from disk='"+path+"';";
SqlConnection con=new SqlConnection("server=.;uid=sa;pwd=;");
SqlCommand cmd=new SqlCommand(restore,con);
try
{
con.Open();
cmd.ExecuteNonQuery();
this.Label1.Text = "恢复成功";
}
catch
{
this.Label1.Text = "恢复失败";
}
finally
{
con.Close();
}
}
}
这是WEB后台程序
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 = "备份成功!";
}
catch
{
this.Label1.Text = "备份失败!";
}
finally
{
con.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string path = @"c:\Test.bak";
string restore="restore database Test from disk='"+path+"';";
SqlConnection con=new SqlConnection("server=.;uid=sa;pwd=;");
SqlCommand cmd=new SqlCommand(restore,con);
try
{
con.Open();
cmd.ExecuteNonQuery();
this.Label1.Text = "恢复成功";
}
catch
{
this.Label1.Text = "恢复失败";
}
finally
{
con.Close();
}
}
}