An example code that backs up and restores a SQL Server database with ASP, hoping to be useful to some friends. (Note: Database may not be recoverable in use)
Copy Code code as follows:
<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.bak" > (file path for backup or recovery) <br>
<input type= "Submit" value= "OK" >
</form>
<%
' Backup and restore of SQL Server database!
' Hai Eva
' Http://www.51windows.Net
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 = 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>