ADO and RDS Objects
OBJECT: Connection
Connection
The ADO
Connection
object provides the means to obtain an open connection to a data source. Through this open connection, you can access and manipulate a database.
In order to query a database, you do not need to explicitly create a
Connection
object. A connection can be made by passing a connection string via a
Command
or
Recordset
object. However, such a connection is only good for that specific, single query. If you desire to access a data source multiple times, it is far more efficient to establish a connection using the
Connection
object.
In a similar vein, you can pass a query string using the
Execute
method of the
Connection
object. However, a
Connection
object query lacks the superior functionality of a
Command
object query.
Only the
Connection
and
Recordset
objects have events. Note that only the Visual Basic, Visual C++, and Visual J++ languages can handle these events. You cannot handle an event using the VBScript or JScript scripting languages.
Carl Prothman of Able Consulting, Inc. maintains a web site containing sample ADO connection strings for ODBC DSN, ODBC DSN-Less, OLE DB Provider, and MS Remote. The Guru highly recommends you visit this extremely useful site.
PROPERTIES
Attributes Property
Sets or returns a long value defining the characteristics of a
Connection
object.
Syntax:
connectionobject.
Attributes
CommandTimeout Property
Sets the number of seconds to wait while attempting an
Execute
method call before terminating the attempt and generating an error message.
Syntax:
connectionobject.
CommandTimeout
ConnectionString Property
Sets or returns a string value that contains the details used to create a connection to a data source.
Syntax:
connectionobject.
ConnectionString
ConnectionTimeout Property
Sets the number of seconds to wait while attempting to create a connection before terminating the attempt and generating an error message.
Syntax:
connectionobject.
ConnectionTimeout
CursorLocation Property
Sets or returns a long value used to select between various cursor libraries accessible through the provider.
Syntax:
connectionobject.
CursorLocation
DefaultDatabase Property
Sets or returns a string value that is the default name of the database available from the provider for a
Connection
object.
Syntax:
connectionobject.
DefaultDatabase
IsolationLevel Property
Sets or returns the transaction isolation level (the
IsolationLevelEnum
value) of a
Connection
object.
Syntax:
connectionobject.
IsolationLevel
Mode Property
Sets or returns the provider access permission (the
ConnectModeEnum
value) for a
Connection
object.
Syntax:
connectionobject.
Mode
Provider Property
Sets or returns the string value that is the provider name.
Syntax:
connectionobject.
Provider
State Property
Returns a long value (the
ObjectStateEnum
value) describing if the connection is open or closed.
Syntax:
connectionobject.
State
Version Property
Returns a string value that is the ADO version number.
Syntax:
connectionobject.
Version
COLLECTIONS
Errors Collection
A collection of
Error
objects that were generated by the failure of a connection operation.
Properties Collection
A collection of
Property
objects. Each
Property
object contains a provider-specific property.
METHODS
BeginTrans Method
Begins a new transaction and returns a long value indicating the number of nested transactions.
Syntax:
connectionobject.
BeginTrans
Cancel Method
Cancels the execution of a pending
Execute
or
Open
call.
Syntax:
connectionobject.
Cancel
Close Method
Closes a connection.
Syntax:
connectionobject.
Close
CommitTrans Method
Saves any changes and ends the current transaction. It can also be set to automatically start a new transaction.
Syntax:
connectionobject.
CommitTrans
Execute Method
Executes the query, SQL statement, stored procedure, or provider-specific text.
Syntax:
connectionobject.
Execute
(CommandText, RecordsAffected, Options)
Open Method
Opens a physical connection to a data source.
Syntax:
connectionobject.
Open
(ConnectionString, UserID, Password, Options)
OpenSchema Method
Returns descriptive schema information from the provider about the data source.
Syntax:
connectionobject.
OpenSchema
(QueryType, Criteria, SchemaID)
RollbackTrans Method
Cancels any changes that have occurred during the current transaction and then ends the transaction. It can also be set to automatically start a new transaction.
Syntax:
connectionobject.
RollbackTrans
EVENTS
BeginTransComplete Event
After a
BeginTrans
operation has finished executing, you can call this event to trigger other operations.
Syntax:
BeginTransComplete
(TransactionLevel, pError, pConnection)
CommitTransComplete Event
After a
CommitTrans
operation has finished executing, you can call this event to trigger other operations.
Syntax:
CommitTransComplete
(pError, adStatus, pConnection)
ConnectComplete Event
After a connection has started, you can call this event to provide information on the success of the connection.
Syntax:
ConnectComplete
(pError, adStatus, pConnection)
Disconnect Event
After a disconnection, you can call this event to provide information on the success of the disconnection.
Syntax:
Disconnect Event
(adStatus, pConnection)
ExecuteComplete Event
After a command has finished executing, you can call this event to provide information on the success of the command and the number of records affected.
Syntax:
ExecuteComplete Event
(RecordsAffected, pError, adStatus, pCommand, pRecordset, pConnection)
InfoMessage Event
This event is called if a warning occurs during a
ConnectionEvent
operation.
Syntax:
InfoMessage
(pError, adStatus, pConnection)
RollbackTransComplete Event
After a
RollbackTrans
operation has finished executing, you can call this event to trigger other operations.
Syntax:
RollbackTransComplete
(TransactionLevel, pError, MessageStatus, pConnection)
WillConnect Event
This event can be called before the connection starts. You can change any of the parameters and even cancel the connection.
Syntax:
WillConnect
(ConnectingString, UserID, Password, Options, adStatus, pConnection)
WillExecute Event
This event is called before a pending command is executed. It allows you to change the execution parameters.
Syntax:
WillExecute Event
(Source, CursorType, LockType, Options, adStatus, pCommand, pRecordset, pConnection)
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information