用ASP備份資料庫 (轉)

worldblog發表於2007-12-14
用ASP備份資料庫 (轉)[@more@]

1:Backup.











Database --&gt Backup
























Server Name: 
Administrators: 
Pass: 
Database:



Backup To:

(Server Path)
 






檔案2:BackupDBSave.asp


dim msvr,muid,mpwd,mdb,mto
msvr=Request.Form("txtsvr")
muid=Request.Form("txtuid")
mpwd=Request.Form("txtpwd")
mdb=Request.Form("txtdb")
mto=Request.Form("txtto")
if mpwd="" then mpwd="''"

on error resume next
set dmosvr=server.Create("DMO.SQLServer")
dmosvr.connect msvr,muid,mpwd

if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

mdevname="Backup_"&muid&"_"&mdb
set dmodev=server.CreateObject("SQLDMO.BackupDevice")
dmodev.name=mdevname
dmodev.type=2
dmodev.PhysicalLocation=mto
dmosvr.BackupDevices.Add dmodev

if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

set dmobak=server.CreateObject("SQLDMO.Backup")
dmobak.database=mdb
dmobak.devices=mdevname
%>




Backu, wait please...


dmobak.sqlbackup dmosvr
if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

dmosvr.backupdevices(mdevname).remove
set dmobak=nothing
set dmodev=nothing
dmosvr.dinnect
set dmosvr=nothing
%>

Database '' backup successed!




檔案3:BackupErr.asp


dim errno,errstr
errno=Request.QueryString("err")
errstr=""
case cstr(errno)
case "18456"
errstr="administrators or password error!"
case "20482"
errstr="server name error or server cannot connect!"
case "911"
errstr="database not found!"
case "15026"
errstr="server path not found!"
case "3201"
errstr="server path not found!"
case "3254"
errstr="restore from file lawlessness!"
case else
errstr="unknown error! retry later please!"
end select
%>




<BR>&lt;!--</P> <P>Sub btnret_onclick<BR>history.back<BR>End Sub</P> <P>--&gt<BR>









來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993065/,如需轉載,請註明出處,否則將追究法律責任。

相關文章