Download SQL database code

Source: Internet
Author: User
<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 Operation: <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> restore </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 recovery file path, backup To EXE mainly for convenient download and live ..) <br>
<Input type = "Submit" value = "OK">
</Form>
<%
Dim sqlserver, sqlname, sqlpassword, sqllogintimeout, databasename, bak_file, Act
Sqlserver = "localhost" 'SQL Server
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, "$1", databasename)
Act = lcase (Request ("act "))
If databasename = "" then
Response. Write "input database name"
Else
If act = "backup" then
Set SRV = server. Createobject ("sqldmo. sqlserver ")
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
'Recovery must be performed when the database is not used!
Set SRV = server. Createobject ("sqldmo. sqlserver ")
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> recovery successful! </Font>"
Else
Response. Write "<font color = Red> no operation selected </font>"
End if
End if
%>
</Body>
</Html>

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.