好像是定义对象的时候没有用New的原因,记住:对象一定要实例化以后才能引用!
解决方案 »
- VB6加水晶报表9,不知怎样传入参数.
- 关于VB自动填写表单的问题,高人快帮我啊
- 求一函数 关于字符串的 高手请进 100分
- 请教如何取得字符串里的每一个字符,谢谢!!!!
- 使用MSHFlexGrid如何能够得到当前鼠标位置下的行坐标??很急的,不好意思没分了,以后绝对补上!!!
- 在datagrid中修改数据时,如何用上下箭头移动到别的单元格
- 请教高手:如何在VB中实现特殊DLL的调用!调用时出现“调用约定错误:49”!请指教!!!
- 有软件开发项目想找人合伙做(用vb开发)
- 各位大侠,小弟在工作中遇到了难题求大家帮忙
- 如何用VB在protel工具栏中添加一个按钮??
- 我用语句生成几个button,谁能都给它们加上这样的功能!
- 谁说懂SOFTWARE就不懂HARDWARE..............一个小软件,需要解决一下,一个ESS“猫”的问题,号称“大虾”的这一帮大哥不妨来看看.......
vb代码:Option ExplicitPrivate maxConnections As Integer
Private availableConnections As New Collection
Private busyConnections As New Collection
Private initialConnections As Integer
Private pending As BooleanPrivate Function makeNewConnection() As ADODB.connection
pending = True
Dim connection As New ADODB.connection
connection.ConnectionTimeout = 30
connection.CommandTimeout = 60
connection.ConnectionString = "PROVIDER=SQLOLEDB.1;DATA SOURCE=192.168.0.3;UID=sa;PWD=;DATABASE=newchina91"
connection.Open
pending = False
makeNewConnection = connection
End FunctionPublic Sub initIt(max As Integer, init As Integer)
maxConnections = max
If init > max Then init = max
initialConnections = init
Dim i As Integer
For i = 1 To initialConnections
availableConnections.Add makeNewConnection()
Next
End SubPublic Function getConnection() As ADODB.connection
Dim connection As ADODB.connection
If availableConnections.Count > 0 Then
Set connection = availableConnections.Item(availableConnections.Count)
availableConnections.Remove (availableConnections.Count)
If connection.State = ADODB.adStateClosed Then
getConnection = getConnection()
Exit Function
Else
busyConnections.Add connection
getConnection = connection
Exit Function
End If
Else
If (totalConnections() < maxConnections) And (Not pending) Then
availableConnections.Add makeNewConnection()
getConnection = getConnection()
Exit Function
Else
getConnection = Null
End If
End If
End FunctionPublic Sub freeConnection(connection As ADODB.connection)
Dim i As Integer
For i = 1 To busyConnections.Count
If busyConnections.Item(i) = connection Then busyConnections.Remove (i)
Next
availableConnections.Add (connection)
End SubPublic Function totalConnections() As Integer
totalConnections = availableConnections.Count + busyConnections.Count
End FunctionPrivate Sub Class_Initialize()
maxConnections = 1
initialConnections = 1
pending = False
End Sub
---------------------------
asp中这样用:set mypool = Server.CreateObject("QxluoPool.ConnectionPool")mypool.initIt 20,1 ‘这一行就出错了!!!!!
why?????
QxluoPool
class module名:
ConnectionPool!!
谢谢!
什么地方错了,为什么错了,请指点!
Private availableConnections As New Collection
Private busyConnections As New Collection
Private initialConnections As Integer
Private pending As Boolean
Dim EADOConnection As New ADODB.connectionPrivate Function makeNewConnection() As String
pending = True
EADOConnection.ConnectionTimeout = 30
EADOConnection.CommandTimeout = 60
EADOConnection.ConnectionString = "PROVIDER=SQLOLEDB.1;DATA SOURCE=10.133.3.179;UID=devuser;PWD=estar123;DATABASE=czefox"
EADOConnection.Open
pending = False
End FunctionPublic Function initIt(max As Integer, init As Integer) As StringOn Error GoTo Errexit:
Dim i As Integer
Dim strResult As String
maxConnections = max
If init > max Then init = max
initialConnections = init
strResult = makeNewConnection()
If Len(strResult) > 0 Then
initIt = strResult
GoTo Errexit
Else
For i = 1 To initialConnections
availableConnections.Add EADOConnection
Next
End If
Errexit:
If Err > 0 Then
initIt = Err.Description
Err = 0
End If
End FunctionPublic Function getConnection() As ADODB.connection
Dim connection As ADODB.connection
If availableConnections.Count > 0 Then
Set connection = availableConnections.Item(availableConnections.Count)
availableConnections.Remove (availableConnections.Count)
If connection.State = ADODB.adStateClosed Then
getConnection = getConnection()
Exit Function
Else
busyConnections.Add connection
getConnection = connection
Exit Function
End If
Else
If (totalConnections() < maxConnections) And (Not pending) Then
availableConnections.Add makeNewConnection()
getConnection = getConnection()
Exit Function
Else
getConnection = Null
End If
End If
End FunctionPublic Sub freeConnection(connection As ADODB.connection)
Dim i As Integer
For i = 1 To busyConnections.Count
If busyConnections.Item(i) = connection Then busyConnections.Remove (i)
Next
availableConnections.Add (connection)
End SubPublic Function totalConnections() As Integer
totalConnections = availableConnections.Count + busyConnections.Count
End FunctionPrivate Sub Class_Initialize()
maxConnections = 1
initialConnections = 1
pending = False
End Sub