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("'Restore From' is empty!") frmbak.txtto.focus exit sub end if frmbak.submit End Sub
<%@ 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)
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 dmores=server.CreateObject("SQLDMO.Restore") dmores.database=mdb dmores.devices=mdevname %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <body class="bg_frame_up">
<p><strong>Restoring, wait please...</strong></p> <% dmores.sqlrestore dmosvr if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)
set dmores=nothing set dmodev=nothing dmosvr.disconnect set dmosvr=nothing %> <p><strong>Database '<%=mdb%>' restore successed!</strong></p> </BODY> </HTML>