ITPub博客

首页 > 数据库 > 数据库开发技术 > 用ASP备份数据库 (转)

用ASP备份数据库 (转)

原创 数据库开发技术 作者:amyz 时间:2007-10-11 13:03:23 0 删除 编辑
用ASP备份数据库 (转)[@more@]

文件1:Backupdb.ASP

<%@ Language=vbscript %>



microsoft FrontPage 4.0">



RM action="backupdbsave.asp" method="post" id=frmbak name=frmbak>

Database --> Backup
























Server Name: 
Administrators: 
Password: 
Database:



Backup To:

(Server Path)
 






文件2:BackupDBSave.asp

<%@ Language=VBScript %>
<%
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.Createobject("sqlDMO.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
%>


Visual Studio 6.0">

Backuping, 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.diSCOnnect
set dmosvr=nothing
%>

Database '<%=mdb%>' backup successed!




文件3:BackupErr.asp

<%@ Language=VBScript %>
<%
dim errno,errstr
errno=Request.QueryString("err")
errstr=""
select 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
%>








<%=errstr%>






来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-975817/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7338889