Connection Object (Versions 2.0, 2.1, 2.5, 2.6)
Dim connection As ADODB.Connection

A Connection object represents a unique connection to a data source. Connection objects are independent of all other ADO objects.

Connection.Attributes Property (Versions 2.0, 2.1, 2.5, 2.6)

Connection.Attributes = XactArgumentsEnum [+ XactArgumentsEnum...]
 

The Attributes property is used to set or return specific characteristics about the Connection object.

Datatype

XactArgumentsEnum (Long)

 
Description

The Attributes property is read- and write-enabled. The value of the Attributes property can be set to any sum of the XactArgumentsEnum enumeration values, listed in Appendix E.

The default value of the Attributes property is zero.

 
Note

Not all providers support the functionality of the Attributes property.

 
See Also

Connection.BeginTrans Method, Connection.CommitTrans Method, Connection.RollBackTrans Method, XactAttributeEnum Enumeration

 
Connection.BeginTrans Method CBT Method(Versions 2.0, 2.1, 2.5, 2.6)

connection.BeginTrans
level = connection.BeginTrans( )
connection.CommitTrans
connection.RollbackTrans
 

The BeginTrans, CommitTrans, and RollbackTrans methods are used to manage transaction processing for the current Connection object.

The BeginTrans method begins a transaction, as you might expect.

The CommitTrans method ends the current transaction, while first saving any changes and then possibly starting another transaction altogether.

The RollbackTrans method ends the current transaction, but rolls back any changes made during the current transaction. In addition, the RollbackTrans method can start another transaction, just as the CommitTrans method can.

Description

The BeginTrans, CommitTrans, and RollbackTrans methods of the Connection object perform transaction management within a particular connection. The most common example of a need for transaction management is a banking system. When you transfer money from one account to another, it is important that the two steps involved (a withdraw followed by a deposit) occur as a single transaction. By using these three transaction-management methods, we can ensure that both or none (but not either alone) of the bank steps are performed. If there is a problem with the deposit after the withdraw has completed, we can in effect roll back time with the RollbackTrans method.

The BeginTrans method begins a new transaction within the current Connection object. By using the BeginTrans method, you can create nested transactions much like you can create nested If . . . Then statements in your code. A return value can be received from the BeginTrans method in the form of a Long, if the data provider supports nested transactions. This return value indicates the level of the nested transaction that was created, one being the first.

The CommitTrans method commits any changes since the beginning of the last transaction. While the RollbackTrans method performs the opposite, it cancels any changes made to the last transaction. In both cases, the last transaction is ended. In addition, the last transaction created must end before either the CommitTrans or RollbackTrans methods can end an earlier transaction.

If the Arguments property of the Connection object is set to adXactCommitRetaining, a new transaction is automatically created after a CommitTrans method call. If this property is set to adXactAbortRetaining, a new transaction is created automatically after a RollbackTrans method call.

 
See Also

Connection.Arguments Property

 
Connection.BeginTransComplete Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub BeginTransComplete(ByVal TransactionLevel As Long, _
ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The BeginTransComplete event is raised after the BeginTrans method has completed its operation.

Arguments
TransactionLevel

A Long value indicating the nesting level of the new transaction.

pError

An Error object containing details about an error that occurred if the adStatus parameter is set to adStatusErrorsOccurred.

adStatus

An EventStatusEnum value indicating the status of the current operation. If the adStatus parameter is set to adStatusOK, the operation was successful. If the adStatus parameter is set to adStatusErrorsOccurred, the operation failed, and the pError object contains the details regarding the error. By setting the adStatus parameter to adStatusUnwantedEvent, this event will not be called again.

pConnection

The Connection object that fired this event.

 
See Also

Connection.BeginTrans Method, Connection.CommitTransComplete Event, Connection.RollbackTransComplete Event, EventStatusEnum Enumeration

 
Connection.Cancel Method (Versions 2.0, 2.1, 2.5, 2.6)

connection.Cancel
 

The Cancel method cancels the pending asynchronous connection or execution.

Description

If the Execute or Open methods of a Connection object where called with the adAsyncConnect, adAsyncExecute, or adAsyncFetch options, the Cancel method will cancel the pending asynchronous operation.

If the Cancel method is called for an operation that was not executed with the adAsyncExecute option set, an error will occur.

 
See Also

Connection.Execute Method, Connection.Open Method

 
Connection.Close Method (Versions 2.0, 2.1, 2.5, 2.6)

connection.Close
 

The Close method is used to close either a Connection or Recordset object, including any dependent objects that they may have.

Description

The Close method terminates a connection with a data source. After a Connection object is closed, properties can be adjusted, and the object can be opened again. Calling methods that require a connection while the Connection object is closed generates an error.

Closing a Connection object that one or more Recordset objects were created from causes those Recordset objects to close as well. All pending changes are lost. If there is a pending transaction, an error occurs.

Closing a Connection object does not remove it from memory, it only frees the resources that it is using. To remove the Connection object from memory in Visual Basic, set it to Nothing.

 
Connection.CommandTimeout Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.CommandTimeout = timeout
 

The CommandTimeout property indicates how long ADO waits before it generates an error when executing a particular command.

Datatype

Long

 
Description

The CommandTimeout property is read- and write-enabled. By using the CommandTimeout property, you can specify how long ADO will wait for a command to execute. The setting for the CommandTimeout property is represented in seconds, and the default value is 30. By setting this property to zero, you are allowing ADO to wait indefinitely for a specified command to execute. If a command does time out, an error will be generated.

The CommandTimeout property of the Command object is unrelated to the CommandTimeout property of the Connection object.

The Connection object's CommandTimeout is read- and write-enabled even when the Connection object is open.

 
Note

Not all providers support the CommandTimeout property.

 
Connection.CommitTrans Method (Versions 2.0, 2.1, 2.5, 2.6)

See the Connection.BeginTrans Method.

Connection.CommitTransComplete Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub CommitTransComplete(ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The CommitTransComplete event is raised after the CommitTrans method completes its operation.

Arguments
pError

An Error object containing details about an error that occurred if the adStatus parameter is set to adStatusErrorsOccurred.

adStatus

An EventStatusEnum value indicating the status of the current operation. If the adStatus parameter is set to adStatusOK, the operation was successful. If the adStatus parameter is set to adStatusErrorsOccurred, the operation failed, and the pError object contains the details regarding the error. By setting the adStatus parameter to adStatusUnwantedEvent, this event will not be called again.

pConnection

The Connection object that fired this event.

 
See Also

Connection.BeginTransComplete Event, Connection.CommitTrans Method, Connection.RollbackTransComplete Event, EventStatusEnum Enumeration

 
Connection.ConnectComplete Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub ConnectComplete(ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The ConnectComplete event is raised once a connection has been made.

Arguments
pError

An Error object containing details about an error that occurred if the adStatus parameter is set to adStatusErrorsOccurred.

adStatus

An EventStatusEnum value indicating the status of the current operation. If the adStatus parameter is set to adStatusOK, the operation was successful. If the adStatus parameter is set to adStatusErrorsOccurred, the operation failed, and the pError object contains the details regarding the error. If the adStatus parameter is set to adStatusUnwantedEvent, this event will not be called again.

pConnection

The Connection object that fired this event.

 
See Also

Connection.Disconnect Event, Connection.WillConnect Event, ConnectOptionEnum Enumeration, EventStatusEnum Enumeration

 
Connection.ConnectionString Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.ConnectionString = connectionstring
 

The ConnectionString property defines the connection used to access a data source.

Datatype

String

 
Description

The ConnectionString property indicates the data source to be used by your connection. You may pass either a DSN (data source name) or a detailed connection string, which is a list of arguments. The arguments must be in the form of argument=value, with multiple arguments separated by a semicolon. If ADO finds an equal sign in the ConnectionString property, it assumes that you are passing a detailed connection string.

 
Arguments

The three supported arguments are listed next. If you pass additional arguments, they are passed directly to the data provider and are not checked by ADO:

Provider

Specifies the name of the data provider to use for the particular connection.

Filename

Specifies the name of a data provider-specific file containing connection information. This argument cannot be used with the Provider argument.

URL

Identifies the absolute URL of a file or directory.

The contents of the ConnectionString property can be altered by ADO at any time after opening the Connection object, so read the property if you are unsure of its contents.

If the ConnectionString argument was used in the Open method of the Connection object, the value is placed within the ConnectionString property of the Connection object.

While the Connection object is open, the ConnectionString is read-only, but when it is closed, it is both read- and write-enabled.

 
See Also

Connection.Open Method

 
Connection.ConnectionTimeout Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.ConnectionTimeout = timeout
 

The ConnectionTimeout property indicates how long in seconds ADO will wait while attempting a connection to a data source.

Datatype

Long

 
Description

By using the ConnectionTimeout property, you can specify how long ADO will wait for a connection to a data source. The setting for the ConnectionTimeout property is represented in seconds. By setting this property to zero, you are allowing ADO to wait indefinitely for a specified connection. If the connection does time out, an error is generated.

The ConnectionTimeout property is read- and write-enabled while the Connection object is closed, but read-only once it is opened.

 
Note

Not all providers support the ConnectionTimeout property.

 
See Also

Connection.Open Method

 
Connection.CursorLocation Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.CursorLocation = CursorLocationEnum
 

The CursorLocation property indicates the location of the cursor service.

Datatype

CursorLocationEnum (Long)

 
Description

The value of the CursorLocation property can be set to one of the valid CursorLocationEnum values, listed in Appendix E.

The value of the CursorLocation property is both read- and write-enabled. However, changing the value of this property affects only Connections that are opened after the value has changed.

 
See Also

Connection.Open Method

 
Connection.DefaultDatabase Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.DefaultDatabase = database
 

The DefaultDatabase property indicates the database that is chosen as the default for the current connection.

Datatype

String

 
Description

The DefaultDatabase property allows the application to specify which database is the default for a Connection object.

Unqualified syntax automatically refers to the database specified by the DefaultDatabase property. Qualifying the object names with the desired database name must be done to access all other databases.

 
Note

Not all providers support the DefaultDatabase property. If they do not, they may raise an error or return an empty String value.

 
Connection.Disconnect Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub Disconnect(adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The Disconnect event is raised once a connection has ended.

Arguments
adStatus

An EventStatusEnum value indicating the status of the current operation. The adStatus parameter is always set to adStatusOK when the event is fired. Setting the adStatus parameter to adStatusUnwantedEvent before leaving the event code means that this event will not be called again.

pConnection

The Connection object that fired this event.

 
See Also

Connection.ConnectComplete Event, EventStatusEnum Enumeration

 
Connection.Errors Collection (Versions 2.0, 2.1, 2.5, 2.6)

Set errors = connection.Errors
 

The Errors collection is a collection of individual errors and warnings that have occurred for the last operation on the current Connection object.

Datatype

Errors (Collection Object)

 
Description

The Errors property of the Connection object is read-only. It returns a reference to the Errors collection object that can contain zero or many Error objects that indicate ADO or provider-specific errors.

 
Connection.Execute Method (Versions 2.0, 2.1, 2.5, 2.6)

connection.Execute CommandText, RecordsAffected, Options
Set recordset = connection.Execute(CommandText, RecordsAffected, Options)
 

The Execute method is used to execute a specified SQL statement, query, stored procedure, URL, or provider-specific command against the data source.

Arguments
CommandText (String)

Optional. Contains the SQL statement, query, stored procedure, URL, or provider-specific command to be executed. The parameter is similar to the Command.CommandText property.

RecordsAffected (Long)

Optional. Contains the number of records that the executed command affected.

Options (Long)

Optional. Represents a combination of one or more CommandTypeEnum and ExecuteOptionEnum values indicating how the data provider should treat the command. The default value is -1 (no options set).

The CommandTypeEnum and ExecuteOptionEnum enumeration values are listed in Appendix E.

 
Returns

RecordsetObject

 
Description

The Execute method executes the command specified by the CommandText parameter, which in turn is evaluated based upon the Options parameter. When the execution of the command is complete, the Connection.ExecuteComplete event is raised.

If the execution of the command returns records, a new Recordset object is returned from the Execute method. If the execution of the command does not return records, an empty Recordset object is returned from the Execute method. Regardless, the Recordset returned is always read-only with a forward-only cursor.

When the Execute method's Options parameter includes one of the adAsyncExecute, adAsyncFetch, or adAsyncFetchNonBlocking values, operations continue in the background of the application flow. While these operations are continuing, the Connection.Cancel method can be called to cancel all pending asynchronous operations.

 
Note

Although the documentation for ADO 2.6 (beta 2) has specified that the CommandText arguments and property can be set to a relative URL, I have found that whatever you set this value to, it is irrelevant. If you wish to obtain the contents of a directory, you must specify the directory in the ConnectionString property. No matter what you specify as the CommandText arguments of the Execute method or the CommandText property of the Connection object, it is ignored. However, if you use an empty String (") as a value, you will receive the error "Errors Occurred."

The following example illustrates how the CommandText property value is irrelevant when calling the Execute method:

Dim con As ADODB.Connection
Dim rec As ADODB.Recordset

Set con = New ADODB.Connection

con.Open "URL=http://jroff_laptop/"

Set rec = con.Execute("nothing really matters")
    
'
' rec contains contents of jroff_laptop
'

rec.Close
con.Close

Set rec = Nothing
Set con = Nothing
 
See Also

Connection.Cancel Method, Command.CommandText Property, Connection.ExecuteComplete Event, CommandTypeEnum Enumeration, ExecuteOptionEnum Enumeration

 
Connection.ExecuteComplete Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub con_ExecuteComplete(ByVal RecordsAffected As Long, _
ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pCommand As ADODB.Command, _
ByVal pRecordset As ADODB.Recordset, _
ByVal pConnection As ADODB.Connection)
 

The ExecuteComplete event is called when the execution of a command has completed.

Arguments
RecordsAffected (Long)

Indicates how many records are affected by the executed command.

pError (Error)

Contains details about an error that occurred if the adStatus parameter is set to adStatusErrorsOccurred.

adStatus (EventStatusEnum)

Indicates the status of the current operation. If the adStatus parameter is set to adStatusOK, the operation was successful. If the adStatus parameter is set to adStatusErrorsOccurred, the operation failed, and the pError object contains the details regarding the error. If the adStatus parameter is set to adStatusUnwantedEvent, this event will not be called again.

pCommand

Represents the Command object that was executed (if there was one).

pRecordset

Represents the Recordset object that results from the commands execution. This Recordset object can be empty.

pConnection

Represents the Connection object that fired this event.

 
See Also

Connection.Execute Method, Command.Execute Method, Recordset.NextRecordset Method, Recordset.Open Method, EventStatusEnum Enumeration

 
Connection.InfoMessage Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub InfoMessage(ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The InfoMessage event is called when a warning is produced during a ConnectionEvent operation.

Arguments
pError

An Error object containing details about an error that occurred if the adStatus parameter is set to adStatusErrorsOccurred.

adStatus

An EventStatusEnum value indicating the status of the current operation. If the adStatus parameter is set to adStatusOK, the operation was successful. If the adStatus parameter is set to adStatusErrorsOccurred, the operation failed, and the pError object contains the details regarding the error. If the adStatus parameter is set to adStatusUnwantedEvent, this event will not be called again.

pRecordset

The Recordset object that fired this event.

 
See Also

EventStatusEnum Enumeration

 
Connection.IsolationLevel Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.IsolationLevel = IsolationLevelEnum
 

The IsolationLevel property is used to set the level of isolation used when utilizing transaction management.

Datatype

IsolationLevelEnum (Long)

 
Description

The IsolationLevel property is both read- and write-enabled. If the value of this property is changed, the effects will not take place until you call the BeginTrans method. If the level of isolation requested couldn't be granted by the data provider, then the next level may be set automatically.

The IsolationLevel property can be set to one of the IsolationLevelEnum enumerations listed in Appendix E.

 
See Also

Connection.BeginTrans Method, IsolationLevelEnum Enumeration

 
Connection.Mode Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.Mode = ConnectModeEnum
 

The Mode property identifies the available permissions for modifying data within the specified connection.

Datatype

ConnectModeEnum (Long)

 
Description

The Mode property is read- and write-enabled while the Connection object is closed, but read-only once it is opened.

The Mode property can be set to one of the ConnectModeEnum enumerations listed in Appendix E.

 
Connection.Open Method (Versions 2.0, 2.1, 2.5, 2.6)

connection.Open ConnectionString, UserID, Password, Options
 

The Open method for the Connection object opens a connection to a particular data source. The Open method for the Recordset object opens a cursor.

Arguments
ConnectionString (String)

Optional. Contains the information needed for ADO to connect to the data provider. This property is mapped to the Connection.ConnectionString property.

UserID (String)

Optional. Contains a username that is used to establish the desired connection.

Password (String)

Optional. Contains a password that is used to establish the desired connection.

Options (Long)

Optional. Represents a ConnectOptionEnum enumeration value. Currently, the only defined value for the ConnectOptionEnum enumeration is adAsyncConnect (16) which instructs ADO to connect to the data source asynchronously. The default value is -1 (no options set).

 
Description

The Open method establishes a connection with a data provider. Once a connection is established, you can issue commands against the data provider and obtain information from the data source.

The connection to a data provider can be established asynchronously by passing the adConnectAsync value to the Options parameter of the Open method. Once the operation has started, the application can call the Connection.Cancel method to cancel the pending asynchronous connection if the application has determined that the connection is taking too long.

The connection to the data provider is defined by the value of the ConnectionString parameter. In addition, the UserName and Password parameters authenticates the user within the data provider. It is possible to set the UserName and Password values in both the ConnectionString and as parameters to the Open method. In such a case, the parameters will override those specified in the ConnectionString property.

The ConnectionString parameter overwrites any value previously set to the Connection.ConnectionString property. In most cases, the ConnectionString property contains more detailed information about the connection then you would pass through the ConnectionString parameter of the Open method. You can read the ConnectionString property to see this added detail.

The ConnectionString parameter, like the ConnectionString property, is constructed of a services of argument=value statements separated by semicolons. The arguments that are used within the ConnectionString parameter (and property) are completely dependent upon the data provider to which you are connecting.

The Connection.Close method is used to close an opened Connection object once the application is done with it. A Connection object that is closed can be altered and reopened again. To remove the Connection object from memory in Visual Basic, set it to Nothing.

 
See Also

Connection.Cancel Method, Connection.Close Method, Connection.ConnectionString Property, ConnectModeEnum Enumeration, ConnectOptionEnum Enumeration

 
Connection.OpenSchema (Versions 2.0, 2.1, 2.5, 2.6)

Set recordset = connection.OpenSchema(Schema, Criteria, SchemaID)
 

The OpenSchema method returns a Recordset object containing information about the data source's schema.

Arguments
Schema (SchemaEnum)

Indicates the type of schema the OpenSchema method will provide in the returned Recordset object.

SchemaEnum contains the enumeration values listed in Table F-1.

Criteria (Variant Array)

Optional. Indicates which constraint columns to use for the Schema requested. A list of each available constraint column for each schema type is listed in Table G-1.

SchemaID (Long)

Optional. Represents a GUID of a provider-specific schema query. If the Schema parameter is set to adSchemaProviderSpecific (-1), then this parameter is mandatory; otherwise, it is not used.

 
Description

The OpenSchema method is used to obtain information about a data source's structure -- its schema.

By setting the Schema parameter to a SchemaEnum value, ADO can determine which information the application is requesting. In addition, the Criteria parameter can be set to narrow the search. For instance, by passing the adSchemaTables enumeration value, the OpenSchema method will only return the table names.

Some providers may support their own schema query types. To use this feature, set the Schema parameter to adSchemaProviderSpecific, and set the SchemaID parameter to the GUID of the provider-specific schema query. If the Schema parameter is set to the adSchemaProviderSpecific value and the SchemaID parameter is not specified, an error will occur.

Not all providers will support all of the schema queries defined in Table G-1. As a matter of fact, only the adSchemaTables, adSchemaColumns, and adSchemaProviderTypes schema queries are supported by all providers. But this still does not guarantee that any of the constraint columns are supported.

 
See Also

SchemaEnum Enumeration

 
Connection.Properties Collection (Versions 2.0, 2.1, 2.5, 2.6)

Set properties = connection.Properties
 

The Properties collection contains characteristics specific to the Connection object for the currently used provider.

Datatype

Properties (Collection Object)

 
Description

The Properties collection class contains a Property class instance for each property specific to the Connection object for the data provider.

The Properties collection of the Connection object contains only the following properties until the Connection is opened:

  • Password

  • Persist Security Info

  • User ID

  • Data Source

  • Window Handle

  • Location

  • Mode

  • Prompt

  • Connect Timeout

  • Extended Properties

  • Locale Identifier

  • Initial Catalog

  • OLE DB Services

  • General Timeout

 
Connection.Provider Property (Versions 2.0, 2.1, 2.5, 2.6)

connection.Provider = provider
 

The Provider property indicates the name of the data provider for the current Connection object.

Datatype

String

 
Description

The Provider property sets the provider for the current Connection object. It can also be specified in the ConnectionString property of the Connection object or the ConnectionString argument to the Open method of the Connection object. It is recommended that the provider be specified in only one of these places, however, because the results can be unpredictable.

The Provider property of the Connection object is read- and write-enabled when the associated Connection object is closed, but read-only once it is open.

The Provider property is not used until the Connection object is opened or the Properties collection of the Connection object is used.

If no provider is specified, ADO will default to MSDASQL, the Microsoft ODBC Provider for OLE DB.

 
See Also

Connection.ConnectionString Property, Connection.Open Method

 
Connection.RollbackTrans Method (Versions 2.0, 2.1, 2.5, 2.6)

See the Connection.BeginTrans Method.

Connection.RollbackTransComplete Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub con_RollbackTransComplete(ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The RollbackTransComplete event is raised after the RollbackTrans method has completed its operation.

Arguments
pError

An Error object containing details about an error that occurred if the adStatus parameter is set to adStatusErrorsOccurred.

adStatus

An EventStatusEnum value indicating the status of the current operation. If the adStatus parameter is set to adStatusOK, the operation was successful. If the adStatus parameter is set to adStatusErrorsOccurred, the operation failed, and the pError object contains the details regarding the error. If the adStatus parameter is set to adStatusUnwantedEvent, this event will not be called again.

pConnection

The Connection object that fired this event.

 
See Also

Connection.BeginTransComplete Event, Connection.CommitTransComplete Event, Connection.RollbackTrans Method, EventStatusEnum Enumeration

 
Connection.State Property (Versions 2.0, 2.1, 2.5, 2.6)

state = connection.State
 

The State property indicates the current status of a Command, Connection, Record, Recordset, or Stream object.

Datatype

ObjectStateEnum (Long)

 
Description

The State property returns a combination of the ObjectStateEnum values, listed in Appendix E, which indicate the current state of an object.

 
See Also

ObjectStateEnum Enumeration

 
Connection.Version Property (Versions 2.0, 2.1, 2.5, 2.6)

version = connection.Version
 

The Version property indicates the current version of ADO in use.

Datatype

String

 
Description

The Version property returns the version information for the version of ADO that you are using in your application, in the form of a String.

 
Connection.WillConnect Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub WillConnect(ConnectionString As String, _
UserID As String, _
Password As String, _
Options As Long, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
 

The WillConnect event is raised before a connection is made.

Arguments
ConnectionString (String)

Contains the connection information for the awaiting connection operation.

UserID (String)

Contains the username for the awaiting connection operation.

Password (String)

Contains the password for the awaiting connection operation.

Options (Long)

Indicates how the ConnectionString parameter should be evaluated. For this parameter, the only valid value is adAsyncOpen.

adStatus (EventStatusEnum)

Indicates the status of the current operation. The adStatus parameter is set to adStatusOK if the operation causing this event was successful. If the adStatus parameter is set to adStatusCantDeny, the event cannot request that the operation be canceled. If the adStatus parameter is set to adStatusUnwantedEvent, this event will not be called again. If the adStatus parameter is set to adStatusCancel, a cancelation request will be made for this operation.

pConnection

Represents the Connection object that fired this event.

 
Note

The ConnectionString, UserID, and Password parameters can be changed by the application within this event before the operation finishes execution.

 
See Also

Connection.ConnectComplete Event, EventStatusEnum Enumeration

 
Connection.WillExecute Event (Versions 2.0, 2.1, 2.5, 2.6)

Private Sub WillExecute(Source As String, _
CursorType As ADODB.CursorTypeEnum, _
LockType As ADODB.LockTypeEnum, _
Options As Long, _
adStatus As ADODB.EventStatusEnum, _
ByVal pCommand As ADODB.Command, _
ByVal pRecordset As ADODB.Recordset, _
ByVal pConnection As ADODB.Connection)
 

The WillExecute event is raised before an execution of a command has begun.

Arguments
Source (String)

Contains the source of the command that is to be executed. This value is usually a SQL statement or a stored procedure name.

CursorType (CursorTypeEnum)

Indicates the type of Recordset object that will be opened. This value can be changed within the event to change the type of cursor that gets used when the Recordset.Open method is called. This parameter is ignored for any other method that causes this event.

LockType (LockTypeEnum)

Indicates the locking scheme that will be used when the Recordset object is opened. This value can be changed within the event to change the locking scheme that gets used when the Recordset.Open method is called. This parameter is ignored for any other method that causes this event.

Options (Long)

Indicates any other options used to execute the command or open the recordset.

adStatus (EventStatusEnum)

Indicates the status of the current operation. The adStatus parameter is set to adStatusOK if the operation causing this event was successful. If the adStatus parameter is set to adStatusCantDeny, the event cannot request that the operation be canceled. If the adStatus parameter is set to adStatusUnwantedEvent, this event will not be called again. By setting the adStatus parameter to adStatusCancel, a cancelation request will be made for this operation.

pCommand

Represents the Command object to which this event applies. Set to Nothing if this event was raised because of a Connection.Execute method or a Recordset.Open method.

pRecordset

Represents the Recordset object to which this event applies. Set to Nothing if this event was raised because of a Connection.Execute method or a Command.Execute method.

pConnection

Represents the Connection object that fired this event.

 
See Also

Connection.Execute Method, Command.Execute Method, Recordset.Open Method, EventStatusEnum Enumeration, LockTypeEnum Enumeration