ASP backup SQL Server database improved version _ Application Tips

Source: Internet
Author: User
Copy Code code as follows:

<form method= "POST" name= "MyForm" action= "Action=backupdatabase" >
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.bak" > (file path for backup or recovery) <br>
<input type= "Submit" value= "OK" id=submit1 name=submit1>
</form>
<%
' Backup and restore of SQL Server database!
If Request ("action") = "BackupDatabase" Then
Dim sqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act
SQL Server = "localhost"
Sqlname = "sa"
SQLPassword = "Password"
Sqllogintimeout = 15
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. Action = 0
Bak. Initialize = 1
' Bak. Replace = True
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
End If
%>
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.