“备份”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是备份文件保存路径
恢复呢,如果用from disk的话,提示说数据库正在使用,不能访问!