ASP備份SQL Server數(shù)據(jù)庫(kù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[br]<% [br]'sql server 數(shù)據(jù)庫(kù)的備份與恢復(fù)! [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]'恢復(fù)時(shí)要在沒(méi)有使用數(shù)據(jù)庫(kù)時(shí)進(jìn)行! [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 "恢復(fù)成功!"[br]else [br]response.write "<font color=red>沒(méi)有選擇操作"[br]end if [br]end if [br]end if[br]%> 該文章在 2010/7/3 14:29:46 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |