ASP program implementation Download SQL database

Source: Internet
Author: User
Tags connect trim backup
Program | data | database | download

<HTML>
<HEAD>
<title>sql Server Database backup and Recovery </TITLE>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
</HEAD>
<BODY>
<form method= "POST" name=myform>
Select actions: <input type= "Radio" name= "act" id= "act_backup" value= "Backup" ><label for=act_backup> backup </label >
<input type= "Radio" name= "act" id= "Act_restore" value= "restore" ><label for=act_restore> recovery </label>
<br> database name: <input type= "text" name= "DatabaseName" value= "<%=request (" DatabaseName ")%>" >
<br> file path: <input type= "text" name= "Bak_file" value= "C:\1.exe" > (Backup or Restore file path, back to exe mainly for easy downloading, alive ...) <br>
<input type= "Submit" value= "OK" >
</form>
<%
Dim sqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act
SQL Server = "localhost"
Sqlname = "sa" User name
SQLPassword = "Database Password" password
sqllogintimeout = 15 ' Login timeout
DatabaseName = Trim (Request ("DatabaseName"))
Bak_file = Trim (Request ("Bak_file"))
Bak_file = replace (Bak_file, "$", databasename)
act = LCase (Request ("act")
if DatabaseName = "" Then
Response.Write "Input Database name"
Else
If act = "Backup" Then
Set srv=server.createobject ("SQLDMO. SQL Server ")
Srv. LoginTimeout = Sqllogintimeout
Srv. Connect Sqlserver,sqlname, SQLPassword
Set bak = Server.CreateObject ("SQLDMO.") Backup ")
Bak. Database=databasename
Bak. Devices=files
Bak. Files=bak_file
Bak. SQLBackup SRV
If Err.number>0 Then
Response.Write err.number& "<font color=red><br>"
Response.Write err.description& "</font>"
End If
Response.Write "<font color=green> backup Successful!</font>"
ElseIf act = "Restore" Then
' Restore when you are not using the database!
Set srv=server.createobject ("SQLDMO. SQL Server ")
Srv. LoginTimeout = Sqllogintimeout
Srv. Connect Sqlserver,sqlname, SQLPassword
Set rest=server.createobject ("SQLDMO. Restore ")
Rest. Action=0 ' Full db restore
Rest. Database=databasename
Rest. Devices=files
Rest. Files=bak_file
Rest. Replacedatabase=true ' Force restore over existing database
If Err.number>0 Then
Response.Write err.number& "<font color=red><br>"
Response.Write err.description& "</font>"
End If
Rest. SQLRestore SRV

Response.Write "<font color=green> Restore Success!</font>"
Else
Response.Write "<font color=red> did not select operation </font>"
End If
End If
%>
</BODY>
</HTML>

Store the above code as ASP, upload



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.