仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1285|回复: 18
打印 上一主题 下一主题

[学习教程] ASP网页编程之ASP完成备份sql server数据

[复制链接]
因胸联盟 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:30:16 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
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

   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>
asp,你就只能等着微软给你解决,它不乐意你就只好悲催。而且asp跑在windows服务器上,windows服务器跟linux比起来简直弱爆了!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-11 18:21

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表