ASP怎么样备份和还原SQLSERVER数据库!代码(急!在线等!)

xiaoxingchi 2003-09-14 02:35:49
ASP怎么样实现备份和还原SQLSERVER数据库的代码!

谢谢!!
...全文
90 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
tigerwen01 2003-10-23
  • 打赏
  • 举报
回复
asp在线备份sql server数据库:
1、备份
<%
SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据备份成功!"
end if
%>

2、恢复
<%
SQL="Restore database 数据库名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据恢复成功!"
end if
%>

注:以上语句是把数据备份到磁盘的backup目录下,文件名为backuptext.dat。

xxrl 2003-10-23
  • 打赏
  • 举报
回复
please to to the website
www.chinabs.net you will find the code .
dishui 2003-10-23
  • 打赏
  • 举报
回复
是SQLSERVER的,不要看到mdb就想成access,不试怎么知道,就是代码长了一些
iamdan 2003-09-16
  • 打赏
  • 举报
回复
ACCESS备份,直接压缩呀。
yhgroup 2003-09-15
  • 打赏
  • 举报
回复
不如继续给出还原的代码,多谢了!
yhgroup 2003-09-15
  • 打赏
  • 举报
回复
dishui(滴水藏海) 说得好啊
xiaoxingchi 2003-09-15
  • 打赏
  • 举报
回复
等了一天了,还是没有人来解决问题!?
SUN1842 2003-09-14
  • 打赏
  • 举报
回复
sql server 的帮助文件中有关于backup设备的记录,在asp中可以调用
xiaoxingchi 2003-09-14
  • 打赏
  • 举报
回复
动网的免费版是ACCESS的,不可能让我去买个动网论坛的SQLSERVER回家去研究!
lang11zi 2003-09-14
  • 打赏
  • 举报
回复
下个动网论坛看看
xiaoxingchi 2003-09-14
  • 打赏
  • 举报
回复
你这个是备份ACCESS数据库的吧!
我想要的是SQLSERVER
dishui 2003-09-14
  • 打赏
  • 举报
回复
上面是备份
dishui 2003-09-14
  • 打赏
  • 举报
回复
文件1:BackupDB.asp
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub btnbak_onclick
if frmbak.txtsvr.value="" then
window.alert("'Server Name' is empty!")
frmbak.txtsvr.focus
exit sub
end if
if frmbak.txtuid.value="" then
window.alert("'Administrators' is empty!")
frmbak.txtuid.focus
exit sub
end if
if frmbak.txtdb.value="" then
window.alert("'Database' is empty!")
frmbak.txtdb.focus
exit sub
end if
if frmbak.txtto.value="" then
window.alert("'Backup To' is empty!")
frmbak.txtto.focus
exit sub
end if
frmbak.submit
End Sub

-->
</SCRIPT>
<link rel="stylesheet" href="../../sheets/B2Bstyle.css">
</HEAD>
<form action="backupdbsave.asp" method="post" id=frmbak name=frmbak>
<body class="bg_frame_up">
<p class=heading> Database --> Backup</p>
<P align=center>
<div align="center">
<center>
<table width="60%" cellpadding=1 cellspacing=1 border=0 align=center>
<tr>
<td class=TD_Mand_FN align="center" height="35" width="40%">Server Name:</td>
<td class=TD_Mand_F height="35" width="59%">
<INPUT id=txtsvr name=txtsvr size="20" style="font-family: Arial; font-size: 9pt"></td>
</tr>
<tr>
<td class=TD_Mand_FN align="center" height="35" width="40%">Administrators:</td>
<td class=TD_Mand_F height="35" width="59%">
<INPUT id=txtuid name=txtuid size="20" style="font-family: Arial; font-size: 9pt"></td>
</tr>
<tr>
<td class=TD_Mand_FN align="center" height="35" width="40%">Password:</td>
<td class=TD_Mand_F height="35" width="59%">
<INPUT id=txtpwd name=txtpwd type=password style="font-family: Arial; font-size: 9pt"></td>
</tr>
<tr>
<td class=TD_Mand_FN align="center" height="35" width="40%">Database:</td>
<td class=TD_Mand_F height="35" width="59%">
<p align="left">
<INPUT id=txtdb name=txtdb size="20" style="font-family: Arial; font-size: 9pt"></p>
</td>
</tr>

<td class=TD_Mand_FN align="center" height="35" width="40%">Backup To:<br>
<u>(Server Path)</u></td>
<td class=TD_Mand_F height="35" width="59%">
<input id=txtto name=txtto style="font-family: Arial; font-size: 9pt"></td>
</tr>
</table>
</center> </div>
<p align=center><input id=btnbak name=btnbak type=button value="Start Backup" style="font-family: Arial; font-size: 9pt"></p>
</body>
</form>
</HTML>


文件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
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<body background="../../Images/dot.gif">

<p><strong>Backuping, wait please...</strong></p>
<%
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
%>
<p><strong>Database '<%=mdb%>' backup successed!</strong></p>
</BODY>
</HTML>


文件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
%>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub btnret_onclick
history.back
End Sub

-->
</SCRIPT>
<title></title>
</HEAD>
<body class="bg_frame_up">
<p align=center><font color=#006666><%=errstr%></font></p>
<p align=center><input id=btnret name=btnret type=button value=Return style="font-family: Arial; font-size: 9pt"></p>
</BODY>
</HTML>
xiaoxingchi 2003-09-14
  • 打赏
  • 举报
回复
能不能给出详细的代码?
luluso 2003-09-14
  • 打赏
  • 举报
回复
触发器。sql方面功夫。
lions911 2003-09-14
  • 打赏
  • 举报
回复
通常使用SQL可视化工具来背份和还原SQL。

可以用ASP雕用SQL对每个数据库生成的SCRIPT语句来生成数据库表结构。

数据本身用ASP很难背份。

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧