你是要用程序实现吗,直接在企业管理器中实现不可以吗
“备份”CLICK事件代码,你参考下:
protected void btnBackup_Click(object sender, System.EventArgs e)
{
string strDBName = txtName.Text.Trim();
string strPath = txtPath.Text.Trim();
if( strDBName == String.Empty )
{
Response.Write("<script>");
Response.Write("alert('请输入数据库名!!!');");
Response.Write("</script>");
return;
}
if( strPath == String.Empty )
{
Response.Write("<script>");
Response.Write("alert('请输入要备份到的路径!!!');");
Response.Write("</script>");
return;
}
DateTime myTime=System.DateTime.Now;
string strDTime = myTime.ToLongDateString();
strDTime += "(";
strDTime += myTime.Hour.ToString("00");
strDTime += myTime.Minute.ToString("00");
strDTime += myTime.Second.ToString("00");
strDTime += ")";
strPath += "SCardDB." + strDTime + ".bak";
DBConn myDB = new DBConn();
string mySql = "backup database " + strDBName + " to disk = '" + strPath + "'";
int i = myDB.Update( mySql );
myDB.Close();
if( i == -1 )
{
Response.Write("<script>");
Response.Write("alert('数据备份成功!!!');");
Response.Write("</script>");
}
}
//txtName 是数据库名 txtPath是备份文件保存路径