ASP数据库恢复的代码

文件4:RestoreDB.asp

1@ Language=VBScript 
 1<html>
 2<head>
 3<meta content="VBScript" name="VI60_defaultClientScript"/>
 4<meta content="Microsoft FrontPage 4.0" name="GENERATOR"/>
 5<script id="clientEventHandlersVBS" language="vbscript">   
 6<!--   
 7  
 8Sub btnbak_onclick   
 9if frmbak.txtsvr.value="" then   
10window.alert("'Server Name' is empty!")   
11frmbak.txtsvr.focus   
12exit sub   
13end if   
14if frmbak.txtuid.value="" then   
15window.alert("'Administrators' is empty!")   
16frmbak.txtuid.focus   
17exit sub   
18end if   
19if frmbak.txtdb.value="" then   
20window.alert("'Database' is empty!")   
21frmbak.txtdb.focus   
22exit sub   
23end if   
24if frmbak.txtto.value="" then   
25window.alert("'Restore From' is empty!")   
26frmbak.txtto.focus   
27exit sub   
28end if   
29frmbak.submit   
30End Sub   
31  
32\-->   
33</script>
34</head>
35<form action="restoredbsave.asp" id="frmbak" method="post" name="frmbak">
36<body class="bg_frame_up">
37<link href="../../sheets/B2BStyle.css" rel="stylesheet"/>
38<p class="heading"> Database --&gt; Restore</p>
39<p align="center">
40<div align="center">
41<center>
42<table align="center" border="0" cellpadding="1" cellspacing="1" height="71" width="60%">
43<tr>
44<td align="center" class="TD_Mand_FN" height="35" width="40%">Server Name:</td>
45<td class="TD_Mand_F" height="35">
46<input id="txtsvr" name="txtsvr" size="20" style="font-family: Arial; font-size: 9pt"/></td>
47</tr>
48<tr>
49<td align="center" class="TD_Mand_FN" height="35" width="40%">Administrators:</td>
50<td class="TD_Mand_F" height="35">
51<input id="txtuid" name="txtuid" style="font-family: Arial; font-size: 9pt"/></td>
52</tr>
53<tr>
54<td align="center" class="TD_Mand_FN" height="35" width="40%">Password:</td>
55<td class="TD_Mand_F" height="35">
56<input id="txtpwd" name="txtpwd" style="font-family: Arial; font-size: 9pt" type="password"/></td>
57</tr>
58<tr>
59<td align="center" class="TD_Mand_FN" height="35" width="40%">Database:</td>
60<td class="TD_Mand_F" height="35">
61<input id="txtdb" name="txtdb" style="font-family: Arial; font-size: 9pt"/></td>
62</tr>
63<tr>
64<td align="center" class="TD_Mand_FN" height="35" width="40%">Restore   
65From:<br/>
66<u>(Server Path)</u></td>
67<td class="TD_Mand_F" height="35">
68<input id="txtto" name="txtto" style="font-family: Arial; font-size: 9pt"/></td>
69</tr>
70</table></center>
71</div>
72<p align="center"><input id="btnbak" name="btnbak" style="font-family: Arial; font-size: 9pt" type="button" value="Start Restore"/></p>
73</p></body>
74</form>
75</html>

文件5:RestoreDBSave.asp

1@ Language=VBScript 
 1   
 2dim msvr,muid,mpwd,mdb,mto   
 3msvr=Request.Form("txtsvr")   
 4muid=Request.Form("txtuid")   
 5mpwd=Request.Form("txtpwd")   
 6mdb=Request.Form("txtdb")   
 7mto=Request.Form("txtto")   
 8if mpwd="" then mpwd="''"   
 9  
10on error resume next   
11set dmosvr=server.CreateObject("SQLDMO.SQLServer")   
12dmosvr.connect msvr,muid,mpwd   
13  
14if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)   
15  
16mdevname="Restore_"&muid&"_"&mdb   
17dmosvr.backupdevices(mdevname).remove   
18err.clear   
19  
20set dmodev=server.CreateObject("SQLDMO.BackupDevice")   
21dmodev.name=mdevname   
22dmodev.type=2   
23dmodev.PhysicalLocation=mto   
24dmosvr.BackupDevices.Add dmodev   
25  
26if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)   
27  
28set dmores=server.CreateObject("SQLDMO.Restore")   
29dmores.database=mdb   
30dmores.devices=mdevname   
1<html>
2<head>
3<meta content="Microsoft Visual Studio 6.0" name="GENERATOR"/>
4</head>
5<body class="bg_frame_up">
6<p><strong>Restoring, wait please...</strong></p>   

dmores.sqlrestore dmosvr
if err.number&gt;0 then Response.Redirect("http:backuperr.asp?err="&amp;err.number)

set dmores=nothing
set dmodev=nothing
dmosvr.disconnect
set dmosvr=nothing

1<p><strong>Database '```
2=mdb
3```' restore successed!</strong></p>
4</body>
5</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus