ASP backup database

Source: Internet
Author: User
Tags microsoft frontpage

File 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.txt svr. value = "" then
Window. alert ("" Server Name "is empty! ")
Frmbak.txt svr. focus
Exit sub
End if
If frmbak.txt uid. value = "" then
Window. alert ("" Administrators "is empty! ")
Frmbak.txt uid. focus
Exit sub
End if
If frmbak.txt db. value = "" then
Window. alert ("Database" is empty! ")
Frmbak.txt db. focus
Exit sub
End if
If frmbak.txt to. value = "" then
Window. alert ("" Backup To "is empty! ")
Frmbak.txt to. 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 = txw.name = txw.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>

File 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 = ".../../webimages/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>

File 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>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.