ActiveConnection Property

The ActiveConnection property on a Command or Recordset object indicates to which Connection object the specified Command or Recordset object currently belongs. This property sets or returns a String containing the definition for a connection or a Connection object. The default is a Null object reference.

command.ActiveConnection = connectionString
activeConnectionString = recordset.ActiveConnection
 

Remarks

The ActiveConnection property is used to determine the Connection object over which the specified Command object will execute or the specified Recordset will be opened.

For Command objects, the ActiveConnection property is read/write.

If you attempt to call the Execute method on a Command object before setting the ActiveConnection property to an open Connection object or valid connection string, an error occurs.

Under Microsoft® Visual Basic®, setting the ActiveConnection property to Nothing disassociates the Command object from the current Connection and causes the OLE DB Provider to release any associated resources on the data source. You can then associate the Command object with the same or another Connection object. Some providers allow you to change the ActiveConnection property setting from one Connection to another, without having to first set the property to Nothing.

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.

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 the ActiveConnection property to a valid Connection object or to a valid connection string. In this case, the OLE DB 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 the ActiveConnection parameter of the Open method is used to open a Recordset object, the ActiveConnection property will inherit the value of the argument.

If the Source property of the Recordset object is set to a valid Command object variable, the ActiveConnection property of the Recordset inherits the setting of the Command object's ActiveConnection property.

The information needed to establish a connection to a data source can be set in the ActiveConnection property of a Recordset object or passed as part of the Open method on a Recordset object in the ActiveConnection parameter. In either case, this information must be in a specific format for use with the Microsoft® OLE DB Provider for AS/400 and VSAM. This information can be a data source name (DSN) or a detailed connection string containing a series of argument=value statements separated by semicolons. ADO supports several standard ADO-defined arguments for the ActiveConnection property as follows:

Argument Description
Data Source Specifies the name of the data source for the connection. This argument is the Data Source name stored in the registry under the OLE DB Provider for AS/400 and VSAM.
File Name Specifies the name of the provider-specific file containing preset connection information. This argument cannot be used if a Provider argument is passed. This argument is not supported by the OLE DB Provider for AS/400 and VSAM.
Password Specifies a valid mainframe or AS/400 password to use when opening the connection. This password is used by Microsoft® SNA Server to validate that the user can log on to the target host system and has appropriate access rights to the file.
Provider Specifies the name of the provider to use for the connection. To use the OLE DB Provider for AS/400 and VSAM the Provider string must be set to "SNAOLEDB".
User ID Specifies a valid mainframe or AS/400 user name to use when opening the connection. This user name is used by SNA Server to validate that the user can log on to the target host system and has appropriate access rights to the file.

The OLE DB Provider for AS/400 and VSAM also supports a number of provider-specific arguments, some of which will default to values in the registry. These arguments are as follows:

Argument Description
CCSID The Code Character Set Identifier (CCSID) attribute indicates the character set used on the host. If this argument is omitted, the default value for CCSID is set to the default value in the registry, typically EBCDIC US English (37).
CodePage The character code page to use on the PC. If this argument is omitted, the default value for CodePage is set to the default value in the registry, typically US ASCII (437). This value is only used when configured for custom code page conversion.
Local LU The name of the local LU alias configured in the SNA server.
Mode The APPC mode (must be set to a value that matches the host configuration and SNA Server configuration). If this argument is omitted, the default value for Mode is set to the default value in the registry.

Legal values for the APPC mode include QPCSUPP (5250), #NTER (interactive), #NTERSC (interactive), #BATCH (batch), #BATCHSC (batch), and custom modes.

RDB The Remote DataBase name for OS/400. You only need to specify this value if it is different from the remote LU alias configured in the SNA server.
Remote LU The name of the remote LU alias configured in the SNA server.