Attributes, methods, events, and constants of three ADO objects (1)

Source: Internet
Author: User

 

Connection object

Attribute

Attribute name data type and purpose
Attributes can read and write the Long type. It specifies whether to use retainning transactions through the sum of two constants ). The constant adXactCommitRetaining indicates that a new transaction is started when the CommitTrans method is called; the constant adXactAbortRetaning indicates that a new transaction is started when the RollbackTrans method is called. The default value is 0, indicating that the reserved transaction is not used.
CommandTimeout can be read and written to the Long type. It specifies the time that must be waited before the Execute call of a related Command object is aborted. The default value is 30 seconds.
ConnectionString can read and write the String type, providing the specific information required by the data provider or service provider to open the connection to the data source
ConnectionTimeout can be read and written to the Long type. It specifies the waiting time before terminating a failed Connection. Open method call. The default value is 15 seconds.
CursorLocation can read and write the Long type. Determine whether the client (adUseClient) cursor engine is used or the server (adUseServer) cursor engine is used. The default value is adUseServer.
DefaultDatabase can read and write data of the String type. If no database name is specified in ConnectString, use the name specified here. for SQL Server, the value is usually pubs.
IsolationLevel can read and write the Long type, specifying the behavior or transaction when interacting with other concurrent transactions. See IsolationLevel constant
Mode Long: Specifies the read and write permissions on the Connection. See Mode constant
Provider can read and write data of the String type. If no ole db data or service Provider name is specified in ConnectionString, the specified name is used. The default value is MSDASQL (Microsoft ole db Provider for ODBC ).
State can be read and written to the Long type, specifying whether the connection is in the open, closed, or intermediate State. See State constant
Version: Read-only String type. The ADO Version number is returned.

Note: Most of the read/write attributes listed above are writable only when the connection is closed.

Only when the user defines the Connection object with the BeginTrans... CommitTrans... RollbackTrans method, can the specified transaction isolation degree be truly effective. If multiple database users execute transactions at the same time, the application must specify how to respond to other transactions in the running state.

Method

Usage
BeginTrans initializes a transaction, which must be followed by CommitTrans and/or RollbackTrans.
Close connection
CommitTrans commits a transaction to change the data source permanently (the BeginTrans method must be called before use)
The Execute select SQL statement returns a forward-only Recordset object, which is also used to Execute statements that do not return Recordset, such as INSERT, UPDATE, DELETE, or DDL statements.
Open uses a connection string To Open a connection.
OpenSchema returns A Recordset object to provide the structure information (metadata) of the data source)
RollbackTrans cancels a transaction and restores temporary changes to the data source (the BeginTrans method must be called before use)

Note: Only the Execute, Open, and OpenSchema methods can accept the variable parameters. Execute Syntax:
CnnName. Execute strCommand, [lngRowsAffected [, lngOptions]
The strCommand value can be an SQL statement, table name, stored procedure name, or any string accepted by the data provider. To improve performance, it is best to specify an appropriate value for the lngOptions parameter (For details, refer to the constant used by the lngOptions parameter) so that the provider does not need to determine its type when interpreting the statement. The optional parameter lngRowsAffected returns the number of values affected after the INSERT, UPDATE, or DELETE statement is executed. These queries return a closed Recordset object. A SELECT query returns the value of lngRowsAffected to 0 and an open forward-only Recordset with one or more rows of content.

Event

Event name trigger time
After the BeginTransComplete BeginTrans method is executed.
Private Sub cnnName_BeginTransComplet (ByVal TransactionLevel As Long, ByVal pError As ADODB. Error, adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
After the CommitTransComplete CommitTrans method is executed
Private Sub connectioncommcommittranscomplete (ByVal pError As ADODB. Error, adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
After ConnectComplete is successfully established to the Connection of the Data Source
Private Sub connection1_complecomplete (ByVal pError As ADODB. Error, adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
After Disconnect Connection is disabled
Private Sub Connection1_Disconnect (adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
When ExecuteComplete completes Connection. Execute or Command. Execute
Private Sub Connection1_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)
When an Error object in InfoMessage is added to the ADODB. Connectio. Error set
Private Sub Connection1_InfoMessage (ByVal pError As ADODB. Error, adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
After the RollbackTransComplete RollbackTrans method is executed
Private Sub connectionrollrollbacktranscomplete (ByVal pError As ADODB. Error, adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
When WillConnect is about to call the Connection. Open Method
Private Sub Connection1_WillConnect (ConnectionString As String, UserID As String, Password As String, Options As Long, adStatus As ADODB. EventStatusEnum, ByVal pConnection As ADODB. Connection)
When WillExecute is about to call the Connection. Execute or Command. Execute Method
Private Sub Connection1_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)

NOTE: For the names and meanings of constants used by the adStatus parameter, see the constants used by the adStatus parameter.

Constant

IsolationLevel constant

Constant meaning
AdXactCursorStability only allows read changes committed by other transactions (default)
AdXactBrowse allows reading uncommitted changes of other transactions
AdXactChaos this transaction will not cover the changes made by other firms located in a higher degree of isolation
AdXactIsolated all transactions are independent of each other
AdXactReadCommitted is equivalent to adXactCursorStability.
AdXactReadUncommitted is equivalent to adXactBrowse
AdXactRepeatableRead disables reading changes to other transactions
AdXactSerializable is equivalent to adXactIsolated
AdXactUnspecified cannot determine the provider's transaction isolation level

Mode constant

Constant meaning
AdModeUnknown connection permission for data source unspecified (default)
AdModeRead connections are read-only.
The adModeReadWrite connection can be read and written.
AdModeShareDenyNone does not reject read/write access from other users (default value of Jet ole db Provider)
AdModeShareDenyRead rejects read connections from other users to the data source.
AdModeShareDenyWrite rejects write connections from other users to the data source.
Admodemo-exclusive open the data source exclusively
The adModeWrite connection is write-only.

State constant

Constant meaning
AdStateClosed Connection (or other objects) is disabled (default)
The status of adStateConnecting connecting to the data source
The Execute method of the adStateExecuting Connection or Command object has been called.
AdStateFetching returns row to Recordset object
AdStateOpen Connection (or other objects) is open (active)

Constants used by the lngOption parameter in the Execute Method

Meaning of constant of Command type
The adCmdUnknown Command type is not fixed (default value). The data provider determines the Command syntax.
Admediafile Command is the file name corresponding to the object type.
AdCmdStoredProc Command is the name of the stored procedure
AdCmdTable Command is the name of a table that can generate an internal SELECT * FROM TableName query.
AdCmdTableDirect Command is the name of the table that can get the row content from the table directly.
AdCmdText Command is an SQL statement.

Constants used by adStatus, A subprocess parameter for ADODB event processing

Constant meaning
The adStatusCancel operation is canceled by the user.
The adStatusCnatDeny operation cannot deny access to the data source from other users.
AdStatusErrorsOccurred operation causes an error and has been sent to the Errors collection
AdStatusOK operation successful
An unexpected event is activated during the adStatusUnWantedEvent operation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.