数据库备份
恢复数据库:
关键字:Alter Database 被恢复的数据库名 Set Offline with Rollback immediate;
restore database 被恢复的数据库名 from disk = '备份文件路径';
Alter Database 被恢复的数据库名 Set OnLine With rollback Immediate;
/////////////////////
string sql = "Alter Database db Set Offline with Rollback immediate;"; //db 是要备份的数据库名
sql += "restore database db from disk = '" ;
sql += Server.MapPath("").ToString() +"\\";
sql += bakname + "'"; //bakname 是备份文件名
sql += "Alter Database db Set OnLine With rollback Immediate;";
try
{
连接 master 数据库 ;
执行 sql 语句;
Response.Write("<script language=javascript>alert('数据恢复成功!');</script>");
}
catch(Exception ex)
{
Response.Write("<script language=javascript>alert('数据恢复失败!');</script>");
this.Label2.Text = ex.ToString();
}
备份数据库:
关键字:backup database 被备份的数据库名 to disk ='备份文件路径';
//////////////////////
string sql = "backup database db to disk = '" + Server.MapPath("").ToString() +"\\"
+ bakname //备份文件名
+ System.DateTime.Now.DayOfYear.ToString()
+ System.DateTime.Now.Millisecond.ToString() + ".bak'";
SQL 2005中的维护计划:[简要如下]恢复数据库:
关键字:Alter Database 被恢复的数据库名 Set Offline with Rollback immediate;
restore database 被恢复的数据库名 from disk = '备份文件路径';
Alter Database 被恢复的数据库名 Set OnLine With rollback Immediate;
/////////////////////
string sql = "Alter Database db Set Offline with Rollback immediate;"; //db 是要备份的数据库名
sql += "restore database db from disk = '" ;
sql += Server.MapPath("").ToString() +"\\";
sql += bakname + "'"; //bakname 是备份文件名
sql += "Alter Database db Set OnLine With rollback Immediate;";
try
{
连接 master 数据库 ;
执行 sql 语句;
Response.Write("<script language=javascript>alert('数据恢复成功!');</script>");
}
catch(Exception ex)
{
Response.Write("<script language=javascript>alert('数据恢复失败!');</script>");
this.Label2.Text = ex.ToString();
}
备份数据库:
关键字:backup database 被备份的数据库名 to disk ='备份文件路径';
//////////////////////
string sql = "backup database db to disk = '" + Server.MapPath("").ToString() +"\\"
+ bakname //备份文件名
+ System.DateTime.Now.DayOfYear.ToString()
+ System.DateTime.Now.Millisecond.ToString() + ".bak'";
右击鼠标,可以看到创建向导,根据创建向导,就能很快的创建工作计划。
...略