欢迎光临
我们一直在努力

无组件的数据库的备份与还原-ASP教程,组件开发

建站超值云服务器,限时71元/月

看过数据库的备份与还原。大多数都是用组件来完成的。其实可通过sql语句来完成。

由于时间关系,未对参数进行验证和界面美化。代码仅供参考。

共计4个文件:下载地址:http://ad.ceh.com.cn/sql.rar

conn.asp

<%

conn="provider=sqloledb.1;persist security info=false;server=127.0.0.1;uid=sa;pwd=www.zhi.net;database=master"

function rec(rs,sql)

set rs = server.createobject("adodb.recordset")

rs.activeconnection = conn

rs.source = sql

rs.cursortype = 0

rs.cursorlocation = 3

rs.locktype = 1

rs.open

if rs.eof and rs.bof then

rec= false

else

rec= true

end if

end function

function cmd(sql)

dim cmd1

set cmd1 = server.createobject("adodb.command")

cmd1.activeconnection = conn

cmd1.commandtext = sql

cmd1.commandtype = 1

cmd1.commandtimeout = 0

cmd1.prepared = true

cmd1.execute()

end function

function cdb(rs)

rs.close()

set rs=nothing

end function

%>

dev.asp

<!–#include file="conn.asp"–>

<%

if request("adddev") <> "" then

sql="select name,phyname from master..sysdevices where status=16 and name="&request("devname")&""

rec chk,sql

if chk.eof and chk.bof then

sql = "sp_addumpdevice disk,"&request("devname")&","&request("phyname")&""

cmd sql

response.write "<script language=javascript>window.location=reload;</script>"

else

response.write "<script language=javascript>alert(数据库中已存在"&request("devname")&"设备!);window.location=cmd.asp;</script>"

end if

end if

if request("deldev") <> "" then

sql = "sp_dropdevice "&request("devname")&""

cmd sql

response.write "<script language=javascript>window.location=reload;</script>"

end if

rec li,"select name,phyname from master..sysdevices where status=16"

if li.eof and li.bof then

response.write "<font color=#ff0000>请新建备份设备用来备份还原数据库</font>"

else

%><style type="text/css">

<!–

body {

margin-left: 0px;

margin-top: 0px;

}

–>

</style>

<table width="60%" border="0" cellspacing="0">

<tr>

<td width="29%">名称:</td>

<td width="71%">位置:</td>

</tr>

<%

i=0

while not li.eof

i=i+1

%>

<tr>

<td><%=li(0)%></td>

<td><%=li(1)%> <a href=dev.asp?deldev=1&devname=<%=li(0)%>>删除此设备</a></td>

</tr>

<%

li.movenext

wend

response.write "<script language=javascript>top.document.all.dev.height="&(i+1)*25&";</script>"

cdb li

%>

</table>

<%

end if

%>

default.asp

<%@language="vbscript" codepage="936"%>

<!–#include file="conn.asp"–>

<%

*************************************************

数据库备份与还原

编 程:魔术师·杨(magicyang.cn)

完成日期:2004-4-11

说明:由于时间关系,未对数据做安全性验证。

应用时请对数据进行验证,确保安全。

qq:1168064 欢迎大家互相交流

*************************************************

%>

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<title>数据库的备份与还原</title>

</head>

<body>

<%

%>

<table width="80%" border="0" align="center">

<tr>

<td width="21%" valign="top">数据库设备:</td>

<td width="79%">

<iframe name="dev" src="dev.asp" width="100%" height="200" frameborder="0" scrolling="no"></iframe>

</td>

</tr>

<tr>

<td>添加设备:</td>

<td>设备名称:

<input name="devname" type="text" id="devname" size="10" maxlength="10"></td>

</tr>

<tr>

<td>&nbsp;</td>

<td>文件路径:

<input name="phyname" type="text" id="phyname" size="20" maxlength="50">

<input type="button" value="添加设备" onclick="document.all.dev.src=dev.asp?adddev=1&devname=+document.all.devname.value+&phyname=+document.all.phyname.value;"></td>

</tr>

<tr>

<td valign="top">备份/还原:</td>

<td>

数据库名称:

<%

rec li,"select name from master..sysdatabases where status=16"

%>

<select name="b_data">

<%

while not li.eof

response.write "<option value="&li(0)&">"&li(0)&"</option>"

li.movenext

wend

cdb li

%>

</select><br>

备份到设备:<%

rec li,"select name,phyname from master..sysdevices where status=16"

%>

<select name="b_dev">

<%

while not li.eof

response.write "<option value="&li(0)&">"&li(0)&"(文件:"&li(1)&")</option>"

li.movenext

wend

cdb li

%>

</select><br>

<input name="按钮" type="button" value="备份数据库" onclick="window.location=cmd.asp?action=backup&database=+document.all.b_data.value+&dev=+document.all.b_dev.value;">

&nbsp;

<input name="按钮" type="button" value="还原数据库" onclick="window.location=cmd.asp?action=restore&database=+document.all.b_data.value+&dev=+document.all.b_dev.value;"> </td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

</table>

</body>

</html>

cmd.asp

<!–#include file="conn.asp"–>

<%

on error resume next

if request("action") <> "" then

if request("action")="backup" then

sql ="backup database "&request("database")&" to "& request("dev")

cmd sql

if err.number > 0 then

response.write "<script language=javascript>alert(数据库"&request("database")&"备份失败!);window.location=default.asp;</script>"

else

response.write "<script language=javascript>alert(数据库"&request("database")&"备份成功!);window.location=default.asp;</script>"

end if

else

sql ="restore database "&request("database")&" from "& request("dev")

cmd sql

if err.number > 0 then

response.write "<script language=javascript>alert(数据库"&request("database")&"还原失败!);window.location=default.asp;</script>"

else

response.write "<script language=javascript>alert(数据库"&request("database")&"还原成功!);window.location=default.asp;</script>"

end if

end if

end if

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 无组件的数据库的备份与还原-ASP教程,组件开发
分享到: 更多 (0)

相关推荐

  • 暂无文章