ASP备份SQL Server数据库
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[br]<% [br]'sql server 数据库的备份与恢复! [br]if request("action")="backupdatabase" then [br]dim sqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act [br]sqlserver = "(local)"[br]sqlname = "pinbo56_f"[br]sqlpassword ="123456"[br]sqllogintimeout = 15[br]databasename = trim(request("databasename")) [br]bak_file = trim(request("bak_file")) [br]bak_file = replace(bak_file,"$1",databasename)[br]act = lcase(request("act"))[br]if databasename = "" then[br]response.write "input database name"[br]else[br]if act = "backup" then[br]set srv=server.createobject("sqldmo.sqlserver")[br]srv.logintimeout = sqllogintimeout[br]srv.connect sqlserver,sqlname, sqlpassword[br]set bak = server.createobject("sqldmo.backup")[br]bak.database=databasename[br]bak.devices=files [br]bak.action = 0[br]bak.initialize = 1[br]'bak.replace = true[br]bak.files=bak_file [br]bak.sqlbackup srv[br]if err.number>0 then [br]response.write err.number&"
" [br]response.write err.description&"" [br]end if[br]response.write "备份成功!" [br]elseif act="restore" then[br]'恢复时要在没有使用数据库时进行! [br]set srv=server.createobject("sqldmo.sqlserver")[br]srv.logintimeout = sqllogintimeout[br]srv.connect sqlserver,sqlname, sqlpassword[br]set rest=server.createobject("sqldmo.restore")[br]rest.action=0 ' full db restore [br]rest.database=databasename [br]rest.devices=files [br]rest.files=bak_file [br]rest.replacedatabase=true 'force restore over existing database [br]if err.number>0 then[br]response.write err.number&" "[br]response.write err.description&""[br]end if[br]rest.sqlrestore srv[br]response.write "恢复成功!"[br]else [br]response.write "<font color=red>没有选择操作"[br]end if [br]end if [br]end if[br]%> 该文章在 2010/7/3 14:29:46 编辑过 |
关键字查询
相关文章
正在查询... |