< %
Const PoolSize = 10
Const Connstr = "Driver={SQL Server};Server=(local);UID=sa;word=555;Database=db"
Function GetRandString(lenth)
Dim rndstr,i
Randomize
rndstr = ""
i = 1
do while i <= lenth
rndstr = rndstr & Chr(cint(((120 - 98 + 1) * Rnd )+ 97))
i = i + 1
loop
GetRandString = rndstr
End Function
Function CreateDbConn()
Dim DbConn,ConnKey
Set DbConn = Server.CreateObject("ADODB.Connection")
DbConn.Open Connstr
ConnKey = GetRandString(10)
DbPool.Add ConnKey,DbConn
End Function
Function GetDbConn()
Dim CurKey,Keys
If DbPool.Count > 0 Then
Keys = DbPool.Keys ' 获取键名。
CurKey = Keys(0)
Response.Write "Cur DbConn Key Is : " & CurKey & "<br />"
Set Conn = Server.CreateObject("ADODB.Connection")
Set Conn = DbPool(CurKey)
If Conn.State = adStateClosed Then '如果这个连接已经关闭,将其从池里注销,再新建一个可用的连接并添加到池里
DbPool.Remove CurKey
Call CreateDbConn() '新建一个连接并添加到池里
Set GetDbConn = GetDbConn()
Else '否则的话,将其从池里注销,然后将复制的对象返回
DbPool.Remove CurKey
Set GetDbConn = Conn
Exit Function
End If
Else
Response.Write "连接池已用完,请重新初始化应用程序"
Response.End
End if
End Function
Function FreeDbConn(DbConn)
DbPool.Add GetRandString(10),DbConn
End Function
<object ID="DbPool" Progid="Scripting.Dictionary" Scope="Application" runat="server"></object> <!--#include file="DbPool.asp"--> < % Sub Application_OnStart Dim ConnKey For i = 1 To PoolSize '建立指定数目的数据库连接 CreateDbConn() Next End Sub Sub Application_OnEnd DbPool.RemoveAll End Sub %>
<!--#include file="DbPool.asp"-->
< %
Response.Write "Test Start:<br>"
Response.Write "Current Objects count : " & DbPool.Count & "<br />"
Set dbconn = Server.CreateObject("ADODB.Connection")
Set dbconn = GetDbConn()
Response.Write "get one connection from pool <br />"
Response.Write "Current Objects count : " & DbPool.Count & "<br />"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open "select * from mkdb",dbconn,1,1
Do While Not rs.eof
Response.write Rs("v_oid") & "<br />"
Rs.movenext
loop
FreeDbConn(dbconn)
Response.Write "free one connection to pool <br />"
Response.Write "Current Objects count : " & DbPool.Count & "<br />"
%>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有