M
Mark J. McGinty
[Bob Barrows, this is more to you than anyone else, but I didn't want to get
stuck in your spam trap]
As I was working on a project, I noticed something interesting about use of
statements such as:
dim cn, rs ' variants
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'cn.Open[...]
rs.ActiveConnection = cn ' note the lack of the Set keyword.
This code actually assigns a Variant/Object/Connection to the
ActiveConnection property, and when you close the connection referenced by
ActiveConnection, cn will show as closed too.
If you instead used:
rs.ActiveConnection = cn.ConnectionString
or any other variable that is of type string (or variant subtype String)
*then* an implicit connection is created, however, it appears, from limited
testing, using ADO 2.8, this morning, here in my scenic office with a window
view, and with full realization that I could be entirely wrong, I might
add... where was I? Oh yeah, it looks like ADO extracts the object from the
variant in which the object is stored, even on a simple assignment.
It's significant to note that these observations were made from within VB6's
debugger, examining a recordset object that was created by/passed-in to a
COM object from script, therefore, all objects are wrapped in variants. It
looks like ActiveConnection is a Variant/Object/Connection unless it's
explicitly set to a connection object. (I'm babbling?)
Anyway, the key factor is whether the connection is wrapped in a variant.
If it is not, then the default property is it's connection string, and a
simple assignment creates an implicit connection. If it is wrapped in a
variant, then the simple assignment assigns one Variant/Object/Connection to
another, and no implicit connection is created and opened.
Here's some script to confuse the issue:
'''''''''''''''''''
Dim cn, rs
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.ConnectionString =
"Provider=SQLOLEDB;Trusted_Connection=Yes;Server=(local);"
cn.Open
rs.ActiveConnection = cn
rs.Open "select * from sysobjects"
Response.Write "Reality check, rs.State = " & rs.State & "<br>"
cn.Close
Response.Write "rs.State = " & rs.State
if rs.State = 0 then
Response.Write ", recordset forced closed when underlying connection was
closed"
else
Response.Write ", someone tell McGinty to STFU"
end if
'''''''''''''''''''
And now that I've blown entirely too much time on Usenet again, I think I'll
get back to work.
-Mark
stuck in your spam trap]
As I was working on a project, I noticed something interesting about use of
statements such as:
dim cn, rs ' variants
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'cn.Open[...]
rs.ActiveConnection = cn ' note the lack of the Set keyword.
This code actually assigns a Variant/Object/Connection to the
ActiveConnection property, and when you close the connection referenced by
ActiveConnection, cn will show as closed too.
If you instead used:
rs.ActiveConnection = cn.ConnectionString
or any other variable that is of type string (or variant subtype String)
*then* an implicit connection is created, however, it appears, from limited
testing, using ADO 2.8, this morning, here in my scenic office with a window
view, and with full realization that I could be entirely wrong, I might
add... where was I? Oh yeah, it looks like ADO extracts the object from the
variant in which the object is stored, even on a simple assignment.
It's significant to note that these observations were made from within VB6's
debugger, examining a recordset object that was created by/passed-in to a
COM object from script, therefore, all objects are wrapped in variants. It
looks like ActiveConnection is a Variant/Object/Connection unless it's
explicitly set to a connection object. (I'm babbling?)
Anyway, the key factor is whether the connection is wrapped in a variant.
If it is not, then the default property is it's connection string, and a
simple assignment creates an implicit connection. If it is wrapped in a
variant, then the simple assignment assigns one Variant/Object/Connection to
another, and no implicit connection is created and opened.
Here's some script to confuse the issue:
'''''''''''''''''''
Dim cn, rs
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.ConnectionString =
"Provider=SQLOLEDB;Trusted_Connection=Yes;Server=(local);"
cn.Open
rs.ActiveConnection = cn
rs.Open "select * from sysobjects"
Response.Write "Reality check, rs.State = " & rs.State & "<br>"
cn.Close
Response.Write "rs.State = " & rs.State
if rs.State = 0 then
Response.Write ", recordset forced closed when underlying connection was
closed"
else
Response.Write ", someone tell McGinty to STFU"
end if
'''''''''''''''''''
And now that I've blown entirely too much time on Usenet again, I think I'll
get back to work.
-Mark