标题: ASP网页编程之ASP完成备份sql server数据 [打印本页] 作者: 因胸联盟 时间: 2015-2-3 23:30 标题: ASP网页编程之ASP完成备份sql server数据 asp可以使用微软的activeX 使得网页功能无比强大,不过安全性也较差,而且是基于的windows服务器,所以性能稳定性也一般server|sql|备份|数据 建个bak文件夹啊,放数据! db.asp代码以下:
<%
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 "没法创立到数据库的毗连!"
end if
%> backup.asp代码以下:
<!--#include file="db.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="EditPlus">
<TITLE> 数据备份体系 </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制造=========
'=====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
'读取表名
Set rs = conn.OpenSchema(20)
Response.Write"<ul><li id='box'>SQL SERVER数据备份剧本</li>"
Do While Not rs.EOF
If rs("TABLE_TYPE") = "TABLE" Then
Response.Write "<li>□ <a href='?table="&rs("TABLE_NAME")&"'>备份 "& 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
' 将字段称号轮回读出
ColCount = Rs.Fields.Count
for intCount= 0 to ColCount-2
sqlBak=sqlBak&rs.Fields(intCount).Name&","
next
'在最初的字段后加括号
sqlBak=sqlBak&Rs.Fields(ColCount-1).Name&")"
sqlHead="INSERT into ["&table&"]("&sqlBak&"values("
do while 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
'最初的字段
'交换单引号
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