ASP backup SQL Server database instance program

Source: Internet
Author: User
Tags trim backup

<HTML>


<HEAD>


<TITLE> Database Operations _ Web Design Home </TITLE>


<meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 ">


</HEAD>





<BODY>


<form method= "POST" name=myform>


<%if action= "restore" then%><input type= "hidden" name= "action" value= "restore" > Ready to restore the database ...


<%elseif action= "Backup" Then%><input type= "hidden" name= "action" value= "Backup" > Prepare to back up the database ... <%else%>


Select operation:


<input type= "Radio" name= "Action" id= "Act_backup" value= "Backup" ><label for=act_backup> backup </label >


<input type= "Radio" name= "Action" id= "Act_restore" value= "restore" ><label for=act_restore> restore </label ><%end if%>


<br> database name: <input type= "text" name= "DatabaseName" value= "50forum" >


<br> file path: <input type= "text" name= "Bak_file" value= "50forum.bak" > (file path for backup or recovery) <br>


<input type= "Submit" value= "OK" >


</form>


<%


' SQL Server database backup and restore!


' http://www.dwww.cn


Dim Sqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act


SQL Server = "localhost" \


sqlname = "sa" User name


sqlpassword = "sa" password


sqllogintimeout = 15 ' Login Timeout


DatabaseName = Trim (Request ("DatabaseName"))


Bak_file = Trim (Request ("Bak_file"))


bak_file = Server.MapPath ("backup/" &bak_file)


act = LCase (Request ("action"))





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. Action = 0


Bak. Initialize = 1


' Bak. ReplaceDatabase = True


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 succeeded!</font>"


Srv.disconnect


Set srv = Nothing


Set bak = Nothing


ElseIf act = "Restore" then


' restore when 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>"


Srv.disconnect


Set srv = Nothing


Set rest = Nothing


Else


Response.Write "<font color=red> did not select operation </font>"


End If


End If


%>


</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.