ASP备份Sql Server数据库

原创 2005年04月30日 21:51:00

<% http://www.acnow.net/ xxcoA1lfx
Dim objSQLServer http://www.acnow.net/ xxcoA1lfx
Dim objBackup http://www.acnow.net/ xxcoA1lfx
Set objSQLServer = Server.CreateObject("SQLDMO.SQLServer") http://www.acnow.net/ xxcoA1lfx
objSQLServer.Connect "Localhost", "sa", "sa" http://www.acnow.net/ xxcoA1lfx
Set objBackup = Server.CreateObject("SQLDMO.Backup") http://www.acnow.net/ xxcoA1lfx
objBackup.Database = "vehicle" http://www.acnow.net/ xxcoA1lfx
objBackup.Files="d:/vehicle.bak" http://www.acnow.net/ xxcoA1lfx
objBackup.MediaDescription = "Back of vehicle" http://www.acnow.net/ xxcoA1lfx
On Error Resume Next http://www.acnow.net/ xxcoA1lfx
objBackup.SQLBackup(objSQLServer) http://www.acnow.net/ xxcoA1lfx
if Err<>0 then http://www.acnow.net/ xxcoA1lfx
strErr = Err.Description http://www.acnow.net/ xxcoA1lfx
response.write strErr http://www.acnow.net/ xxcoA1lfx
else http://www.acnow.net/ xxcoA1lfx
response.write "&Ecirc;&yacute;&frac34;&Yacute;&sup3;&Eacute;&sup1;&brvbar;±&cedil;·&Yacute;!" http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
%>

http://www.acnow.net/ B7W6bI

2. http://www.acnow.net/ xxcoA1lfx
文件1:BackupDB.asp

<%@ Language=VBscript %> http://www.acnow.net/ xxcoA1lfx
<HTML> http://www.acnow.net/ xxcoA1lfx
<HEAD> http://www.acnow.net/ xxcoA1lfx
<meta name=VI60_defaultClientscript content=VBscript> http://www.acnow.net/ xxcoA1lfx
<meta NAME="GENERATOR" Content="Microsoft FrontPage 4.0"> http://www.acnow.net/ xxcoA1lfx
<script ID=clientEventHandlersVBS LANGUAGE=vbscript> http://www.acnow.net/ xxcoA1lfx
<!--btnbak_onclick http://www.acnow.net/ xxcoA1lfx
if frmbak.txtsvr.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Server Name' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtsvr.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
if frmbak.txtuid.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Administrators' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtuid.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
if frmbak.txtdb.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Database' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtdb.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
if frmbak.txtto.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Backup To' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtto.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
frmbak.submit http://www.acnow.net/ xxcoA1lfx
End Sub--> http://www.acnow.net/ xxcoA1lfx
</script> http://www.acnow.net/ xxcoA1lfx
<link rel="stylesheet" href="../../sheets/B2BStyle.css"> http://www.acnow.net/ xxcoA1lfx
</HEAD> http://www.acnow.net/ xxcoA1lfx
<form action="backupdbsave.asp" method="post" id=frmbak name=frmbak> http://www.acnow.net/ xxcoA1lfx
<body class="bg_frame_up"> http://www.acnow.net/ xxcoA1lfx
<p class=heading> Database --> Backup</p> http://www.acnow.net/ xxcoA1lfx
<P align=center> http://www.acnow.net/ xxcoA1lfx
<div align="center"> http://www.acnow.net/ xxcoA1lfx
<center> http://www.acnow.net/ xxcoA1lfx
<table width="60%" cellpadding=1 cellspacing=1 border=0 align=center> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Server Name:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtsvr name=txtsvr size="20" style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Administrators:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtuid name=txtuid size="20" style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Password:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtpwd name=txtpwd type=password style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Database:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<p align="left"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtdb name=txtdb size="20" style="font-family: Arial; font-size: 9pt"></p> http://www.acnow.net/ xxcoA1lfx
</td> http://www.acnow.net/ xxcoA1lfx
</tr>http://www.acnow.net/ xxcoA1lfx

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

http://www.acnow.net/ xxcoA1lfx

http://www.acnow.net/ xxcoA1lfx
文件2:BackupDBSave.asp

http://www.acnow.net/ xxcoA1lfx

<%@ Language=VBscript %> http://www.acnow.net/ xxcoA1lfx
<% http://www.acnow.net/ xxcoA1lfx
dim msvr,muid,mpwd,mdb,mto http://www.acnow.net/ xxcoA1lfx
msvr=Request.Form("txtsvr") http://www.acnow.net/ xxcoA1lfx
muid=Request.Form("txtuid") http://www.acnow.net/ xxcoA1lfx
mpwd=Request.Form("txtpwd") http://www.acnow.net/ xxcoA1lfx
mdb=Request.Form("txtdb") http://www.acnow.net/ xxcoA1lfx
mto=Request.Form("txtto") http://www.acnow.net/ xxcoA1lfx
if mpwd="" then mpwd="''"

http://www.acnow.net/ xxcoA1lfx

on error resume next http://www.acnow.net/ xxcoA1lfx
set dmosvr=server.CreateObject("SQLDMO.SQLServer") http://www.acnow.net/ xxcoA1lfx
dmosvr.connect msvr,muid,mpwd

http://www.acnow.net/ xxcoA1lfx

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

http://www.acnow.net/ xxcoA1lfx

mdevname="Backup_"&muid&"_"&mdb http://www.acnow.net/ xxcoA1lfx
set dmodev=server.CreateObject("SQLDMO.BackupDevice") http://www.acnow.net/ xxcoA1lfx
dmodev.name=mdevname http://www.acnow.net/ xxcoA1lfx
dmodev.type=2 http://www.acnow.net/ xxcoA1lfx
dmodev.PhysicalLocation=mto http://www.acnow.net/ xxcoA1lfx
dmosvr.BackupDevices.Add dmodev

http://www.acnow.net/ xxcoA1lfx

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

http://www.acnow.net/ xxcoA1lfx

set dmobak=server.CreateObject("SQLDMO.Backup") http://www.acnow.net/ xxcoA1lfx
dmobak.database=mdb http://www.acnow.net/ xxcoA1lfx
dmobak.devices=mdevname http://www.acnow.net/ xxcoA1lfx
%> http://www.acnow.net/ xxcoA1lfx
<HTML> http://www.acnow.net/ xxcoA1lfx
<HEAD> http://www.acnow.net/ xxcoA1lfx
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> http://www.acnow.net/ xxcoA1lfx
</HEAD> http://www.acnow.net/ xxcoA1lfx
<body background="../../Images/dot.gif">

http://www.acnow.net/ xxcoA1lfx

<p><strong>Backuping, wait please...</strong></p> http://www.acnow.net/ xxcoA1lfx
<% http://www.acnow.net/ xxcoA1lfx
dmobak.sqlbackup dmosvr http://www.acnow.net/ xxcoA1lfx
if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

http://www.acnow.net/ xxcoA1lfx

dmosvr.backupdevices(mdevname).remove http://www.acnow.net/ xxcoA1lfx
set dmobak=nothing http://www.acnow.net/ xxcoA1lfx
set dmodev=nothing http://www.acnow.net/ xxcoA1lfx
dmosvr.disconnect http://www.acnow.net/ xxcoA1lfx
set dmosvr=nothing http://www.acnow.net/ xxcoA1lfx
%> http://www.acnow.net/ xxcoA1lfx
<p><strong>Database '<%=mdb%>' backup successed!</strong></p> http://www.acnow.net/ xxcoA1lfx
</BODY> http://www.acnow.net/ xxcoA1lfx
</HTML>

http://www.acnow.net/ xxcoA1lfx

http://www.acnow.net/ xxcoA1lfx
文件3:BackupErr.asp

http://www.acnow.net/ xxcoA1lfx

<%@ Language=VBscript %> http://www.acnow.net/ xxcoA1lfx
<% http://www.acnow.net/ xxcoA1lfx
dim errno,errstr http://www.acnow.net/ xxcoA1lfx
errno=Request.QueryString("err") http://www.acnow.net/ xxcoA1lfx
errstr="" http://www.acnow.net/ xxcoA1lfx
select case cstr(errno) http://www.acnow.net/ xxcoA1lfx
case "18456" http://www.acnow.net/ xxcoA1lfx
errstr="administrators or password error!" http://www.acnow.net/ xxcoA1lfx
case "20482" http://www.acnow.net/ xxcoA1lfx
errstr="server name error or server cannot connect!" http://www.acnow.net/ xxcoA1lfx
case "911" http://www.acnow.net/ xxcoA1lfx
errstr="database not found!" http://www.acnow.net/ xxcoA1lfx
case "15026" http://www.acnow.net/ xxcoA1lfx
errstr="server path not found!" http://www.acnow.net/ xxcoA1lfx
case "3201" http://www.acnow.net/ xxcoA1lfx
errstr="server path not found!" http://www.acnow.net/ xxcoA1lfx
case "3254" http://www.acnow.net/ xxcoA1lfx
errstr="restore from file lawlessness!" http://www.acnow.net/ xxcoA1lfx
case else http://www.acnow.net/ xxcoA1lfx
errstr="unknown error! retry later please!" http://www.acnow.net/ xxcoA1lfx
end select http://www.acnow.net/ xxcoA1lfx
%> http://www.acnow.net/ xxcoA1lfx
<HTML> http://www.acnow.net/ xxcoA1lfx
<HEAD> http://www.acnow.net/ xxcoA1lfx
<meta name=VI60_defaultClientscript content=VBscript> http://www.acnow.net/ xxcoA1lfx
<meta NAME="GENERATOR" Content="Microsoft FrontPage 4.0"> http://www.acnow.net/ xxcoA1lfx
<script ID=clientEventHandlersVBS LANGUAGE=vbscript> http://www.acnow.net/ xxcoA1lfx
<!--

btnret_onclick http://www.acnow.net/ xxcoA1lfx
history.back http://www.acnow.net/ xxcoA1lfx
End Sub

--> http://www.acnow.net/ xxcoA1lfx
</script> http://www.acnow.net/ xxcoA1lfx
<title></title> http://www.acnow.net/ xxcoA1lfx
</HEAD> http://www.acnow.net/ xxcoA1lfx
<body class="bg_frame_up"> http://www.acnow.net/ xxcoA1lfx
<p align=center><font color=#006666><%=errstr%></font></p> http://www.acnow.net/ xxcoA1lfx
<p align=center><input id=btnret name=btnret type=button value=Return style="font-family: Arial; font-size: 9pt"></p> http://www.acnow.net/ xxcoA1lfx
</BODY> http://www.acnow.net/ xxcoA1lfx
</HTML>

在asp.net中备份还原SQL Server数据库

在web中,安全性主要体现在两个方面:一个是程序安全性,即防止网页在插入恶意代码;另一个是数据库安全性,这个我们可以经常备份数据库来实现。 在文中,我将演示如果在网页中备份和恢复数据库。 其实备份...

ASP.NET下对远程SQL SERVER数据库的备份和恢复

Sql server的帮助文档地址,在IE里面直接输入就行 mk:@MSITStore:C:\Program%20Files\Microsoft%20SQL%20Server\80\Tools\Bo...

c# asp.net实现sql server数据库备份

  • 2008年10月18日 12:23
  • 120KB
  • 下载

ASP.NET备份恢复SQL Server数据库

  • 2008年02月07日 20:33
  • 28KB
  • 下载

SQL Server2014数据库的备份和还原

在系统开发的过程中,把DB备份,并还原到其他的服务器上,或者在本机上在还原出一个数据库的操作很常见。 大概步骤是: 1.以sa账号登录,在需要备份的DB上选择右键->任务->备份 2. ...
  • zpf0901
  • zpf0901
  • 2017年04月25日 17:09
  • 1849

使用SQL Server维护计划实现数据库定时自动备份

在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库。而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求管理员每天守到晚上1点去备份数据库。要实现数据库的定...

SQL SERVER数据库备份恢复

  • 2006年02月23日 09:05
  • 452KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ASP备份Sql Server数据库
举报原因:
原因补充:

(最多只允许输入30个字)