关于将连接对象设成nothing

此处示例一个中间层组件的方法,交易类型为requiresTransaction
Public Sub testInnerConn()
Dim conn As ADODB.Connection
Dim conn1 As ADODB.Connection
Dim conn2 As ADODB.Connection
Dim conn3 As ADODB.Connection
Dim conn4 As ADODB.Connection
Dim conn5 As ADODB.Connection
Dim conn6 As ADODB.Connection
Dim rec As ADODB.Recordset
Set conn = modVBMiddle.GetConnectionObject("HQ_TEST")
'App.LogEvent "get the conn"
'conn.Open
Set rec = conn.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn = Nothing
Sleep 5000
Set conn1 = modVBMiddle.GetConnectionObject("HQ_TEST")
Set rec = conn1.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn1 = Nothing
Sleep 5000
Set conn2 = modVBMiddle.GetConnectionObject("HQ_TEST")
Set rec = conn2.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn2 = Nothing
Sleep 5000
Set conn3 = modVBMiddle.GetConnectionObject("HQ_TEST")
Set rec = conn3.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn3 = Nothing
Sleep 5000
Set conn4 = modVBMiddle.GetConnectionObject("HQ_TEST")
Set rec = conn4.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn4 = Nothing
Sleep 5000
Set conn5 = modVBMiddle.GetConnectionObject("HQ_TEST")
Set rec = conn5.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn5 = Nothing
Sleep 5000
Set conn6 = modVBMiddle.GetConnectionObject("HQ_TEST")
Set rec = conn6.Execute("select username,sid,serial# from v$session where USERNAME = 'PKUSER'")
App.LogEvent "conn num:" + CStr(rec.RecordCount)
Set conn6 = Nothing
Sleep 5000
End Sub

其中App.LogEvent 是将连接数写如日志
结果令我惊讶:一次查到的连接数目为:1,2,2,2,2,2........
connection.close可以确保连接在同事务环境中被复用,如果只是将连接setnothing,只能说表现诡异.....

你可能感兴趣的:(对象)