ActiveConnection Property
Indicates to which Connection object the
specified Command or Recordset
object currently belongs.
Settings and Return Values
Sets or returns a String containing the definition for a connection or
a Connection object reference. Default is Null.
Remarks
Use the ActiveConnection property to set or return an open Connection
object over which the specified Command object should execute or the
specified Recordset should be opened. If you pass a connection string
for this argument, ADO opens a new connection using the specified parameters.
Command
For Command objects, the ActiveConnection property is
read/write.
If you attempt to call the Execute method on a Command
object before setting this property to an open Connection object or
valid connection string, an error occurs.
Setting this property to Nothing disassociates the Command
object from the current Connection and causes the provider to release
any associated resources on the data source. You can then associate the Command
object with the same or another Connection object. If the Parameters
collection of the Command object contains parameters supplied by the
provider, the collection is cleared if you set the ActiveConnection
property to Nothing or to another Connection object. If you
manually create Parameter objects and use them
to fill the Parameters collection of the Command object, setting
the ActiveConnection property to Nothing or to another Connection
object leaves the Parameters collection intact.
Closing the Connection object with which a Command object is
associated sets the ActiveConnection property to Nothing.
Setting this property to a closed Connection object generates an error.
Recordset
For open Recordset objects or for Recordset objects whose Source
property is set to a valid Command object, the ActiveConnection
property is read-only. Otherwise, it is read/write.
You can set this property to a valid Connection object or to a valid
connection string. In this case, the provider creates a new Connection
object using this definition and opens the connection. Additionally, the
provider may set this property to the new Connection object to give you
a way to access the Connection object for extended error information or
to execute other commands.
If you use the ActiveConnection argument of the Open
method to open a Recordset object, the ActiveConnection property
will inherit the value of the argument.
If you set the Source property of the Recordset object to a
valid Command object variable, the ActiveConnection property of
the Recordset inherits the setting of the Command object's ActiveConnection
property.
Applies To
Command, Recordset
|