server|sql| Backup | data
Build a Bak folder Ah, put the data!
The db.asp code is as follows:
<%
Dim conn
Dim connstr
' On Error Resume Next
Set Conn=server. CreateObject ("Adodb.connection")
Connstr= "Provider=sqloledb;data source=192.168.2.1; Uid=sa; Pwd=123;database=test "
Conn. Open ConnStr
If Err<>0 Then
Response.Write "Unable to establish a connection to the database!" "
End If
%>
The backup.asp code is as follows:
<!--#include file= "db.asp"-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<meta name= "generator" content= "EditPlus" >
<TITLE> Data backup System </TITLE>
<style type= "Text/css" >
A{color:fff;text-decoration:none;}
A:hover{color:ccc;text-decoration:underline;}
ul{border-top:1px solid #fff;
border-left:1px solid #fff;
border-right:1px solid #fff;
margin:0px;
width:400px;}
li{list-style:none;border-bottom:1px solid #fff; height:25px;padding:4px;text-align:left;}
#box {list-style:none;border-bottom:1px solid #fff; height:25px;padding:4px;text-align:center;}
body{
Background: #037EC5;
Color: #fff;
font-size:12px;
Text-align:center;
Font-family:tahoma;
margin:0px;
}
#bak {position:absolute;
left:360px;
top:100px;
height:40px;
border:1px solid #ccc;
padding:20px;
Filter:alpha (opacity=75);
Background: #fff;
Color: #000;
}
</style>
</HEAD>
<BODY>
<%
server.scripttimeout=1000
On Error Resume Next
'====================
' =====xhtml made =========
' =====2005-3-31======
function CreateFile (SQL)
Dim FSO, Tf,filename
Filename=replace (replace (now (), "", "-"), ":", "-") & ". sql"
Filename=server.mappath ("bak/" &table&filename)
Set fso = CreateObject ("Scripting.FileSystemObject")
Set tf = fso. CreateTextFile (filename, True)
Tf. WriteLine "SET identity_insert [" &table&] on "
Tf. WriteLine SQL
Tf. WriteLine "SET identity_insert [" &table& "] off"
Tf. Close
End Function
' Read table name
Set RS = conn. OpenSchema (20)
Response.Write "<ul><li id= ' box ' >sql Server Data backup script </li>"
Do but not Rs. Eof
If rs ("table_type") = "TABLE" Then
Response.Write "<li>-<a href= '? table=" &rs ("table_name") & "' > Backup" & RS ("table_name") & " </a></li> "
End If
Rs. MoveNext
Loop
Response.Write "</ul>"
Set rs = Nothing
Table=request.querystring ("table")
If table<> "" Then
Mysql= "SELECT * from" &table
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open mysql,conn,1,1
' Cycle the field name to read
ColCount = Rs.Fields.Count
For intcount= 0 to ColCount-2
Sqlbak=sqlbak&rs. Fields (intcount). name& ","
Next
' After the last field with parentheses
Sqlbak=sqlbak&rs.fields (ColCount-1). name& ")"
sqlhead= INSERT into [&table&] ("&sqlBak&" VALUES ("
Do as not rs.eof
For intcount= 0 to ColCount-2
Mainstr=replace (Rs.fields (intcount). Value, "'", "" "
If Rs.fields (intcount). Type=3 Then
sqldata=sqldata&mainstr& ","
Else
sqldata=sqldata& "'" &mainSTR& "',"
End If
Next
' The last field
' Replace single quotes
Laststr=replace (Rs.fields (ColCount-1). Value, "'", "" "
If Rs.fields (ColCount-1). Type=3 Then
sqldata=sqldata&laststr& ")" &vblf&sqlhead
Else
sqldata=sqldata& "'" &lastSTR& "" &vblf&sqlhead
End If
Rs.movenext
Loop
Sqldata=sqlhead&sqldata
Sqllong=len (SqlData)-len (Vblf&sqlhead)
Sqldata=left (Sqldata,sqllong)
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
CreateFile (SqlData)
Else
Response.End
End If
%>
</BODY>
</HTML>