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

zhaozj2021-02-17  50

Connection object

Attributes

Attribute name data type and purpose

Attributes can read and write long types, with two constants and specify whether to use retention transactions (Retainning Transactions). Constant ADXACTCommitRetaining indicates a new transaction when calling a committrans method; constant adxactabortretaning means that a new transaction is initiated when calling the RollbackTrans method. The default is 0, indicating that it does not use the retained transaction.

CommandTimeout reads the long type to specify the time you must wait until the Execute call for a relevant Command object. The default is 30 seconds.

Connectionstring Read Write String Type, provides specific information required to provide a data provider or service provider to open to a data source

ConnectionTIMEOUT can read and write long types, specify that the time you must wait for a failure of a failed Connection.Open method call, the default is 15 seconds.

CursorLocation Reads LONG Type, determined to use the client (ADUSECLIENT) cursor engine, or use the server-side cursor engine. The default is aduseserver.

DEFAULTDATABASE reads and writes String type. If you do not specify a database name in ConnectString, you will use the name specified here. For SQL Server, its value is usually PUBS.

IsolationLevel reads the long type, specifying and other parallel transactions interacting behavior or transactions. See ISOLATIONLEVEL constant

Mode long type, specify read and write permissions to Connection. See MODE constant

Provider reads and writes String type, if you do not specify an OLE DB data or service provider's name in Connectionstring, use the name specified at this time. The default is MSDasql (Microsoft Ole DB Provider for ODBC).

State Readable LONG Type, specifying the connection is in an open state, or is in a closed state or an intermediate state. See State constant

Version read-only String type, returns the ADO version number.

Note: Most of the readable and writable properties listed above, only when the connection is in turn off, it is written.

Only when the user uses the BeGintrans ... CommitTrans ... RollbackTrans method defines the specified for the degree of transaction isolation. If there are multiple database users to execute transactions at the same time, the application must specify how to respond to other transactions in the run.

method

Method use

BeGintrans initializes a transaction; there must be COMMITTRANS and / or ROLLBACKTRANS

Close Close connection

CommitTrans submits a transaction to complete the permanent change of the data source (Begintrans method must be called before use)

The EXECUTE SELECT SQL statement returns a Forward-Only Recordset object, and it is also used to perform those who do not return a Recordset statement, such as INSERT, UPDATE, DELETE query, or DDL statement.

Open uses a connection string to open a connection

OpenSchema returns a RECORDSET object to provide the data source structure information (Metadata)

RollbackTrans cancels a transaction, restores a temporary change for the data source (Begintrans method must be called before use)

Note: Three ways that execute, Open, and OpenSchema can accept variable parameters. Execute's grammar is: cnnname.execute strcommand, [lngrowsaffected [, lngoptions]]

The value of strcommand can be a SQL statement, a table name, and a stored procedure name, or any string that the data provider can accept. In order to improve performance, it is best to specify a suitable value for the LNGOptions parameter (see the constant for the LNGOptions parameter) to enable the provider to explain the statement without determining its type. Optional parameters LNGROWSAFFECTED will return the number of INSERT, UPDATE, or DELETE queries. These queries returns an off Recordset object. A SELECT query will return the LNGROWSAFFECTED value of 0 and return Forward-Only RecordSet with a row or multi-line content.

event

Event name trigger time

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

Private sub connection1_commitTranscomplete (Byval Perror As AdoDb.Error, Adstatus As Adod.EventStatusenum, ByVal PConnection As Adodb.Connection)

After the ConnectComplete successfully established the connection to the data source

Private sub connection1_connectcomplete (byval perror as adoDb.error, adstatus as adodb.eventstatusenum, byval pconnection as adoDb.connection)

DiSConnect Connection is turned off

Private sub connection1_disconnect (adstatus as adodb.eventStatusenum, byval pconnection as adodb.connection)

EXECUTECOMPLETE When constant 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)

InfubusSage An error object is added to the AdoDb.Connectio.Error collection

Private sub connection1_infomessage (byval perror as adoDb.error, adstatus as adodb.eventstatusenum, byval pConnection as adodb.connection)

RollbackTranscomplete RollbackTransComplete RollbackTransComplete RollbackTransComplete RollbackTransComplete

Private sub connection1_rollbacktranscomplete (byval perror as adodb.error, adstatus as adodb.EventStatusenum, byval pConnection as adoDb.connection) WillConnect is about to call Connection.Open methods

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)

Willexecute is about to call 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: The name and meaning of the constant used in the AdStatus parameters are detailed in the constant used by Adstatus.

constant

IsolationLevel constant

Constant meaning

ADXACTCURSORSTABILITY only allows you to read other transactions (default)

ADXACTBROWSE allows you to read other transactions

The ADXACTCHAOS This business does not overwrite changes made by other levels of isolation.

ADXACTISOLATED all the transactions

ADXACTREADCOMMITTED is equivalent to ADXACTCURSORSTABILITY

ADXACTREADUNCOMMITTED is equivalent to ADXACTBROWSE

ADXACTREPEATABLEREAD prohibits reading other transactions

ADXACTSERIALIZABLE is equivalent to ADXACTISOLATED

ADXACTUNSPECIFIED cannot determine the degree of transaction isolation of the provider

Mode constant

Constant meaning

AdmodeunkNown does not specify the connection permission of the data source (default)

The AdmodeRead connection is read-only.

AdmodeReadwrite connection is readable

Admodesharedenynne does not reject other users' read and write access (the default value of Jet OLE DB Provider)

AdmodesharednyRead rejects other users to open a read connection to the data source

AdmodesharedenYwrite Rejects other users to open a write connection to the data source

AdmodesharexClusive opens the data source exclusive way

The AdmodeWrite connection is only written.

State constant

Constant meaning

AdStateClosed Connection is off (default)

AdStateConnecting is connected to the status of the data source

The Execute method of the AdstateExecuting Connection or Command object has been called

AdstateFetching Return (ROW) to the Recordset object

AdStateOpen Connection (or other object) is open (activity)

Constant for LNGOption parameters in the execute method

Command type constant meaning

AdcmDunkNown Command Type Unexpected (Default)

AdcmdStoredProc Command is a stored procedure name

AdcmdTable Command is a table name that can generate internal Select * from tablename queries

AdcmdtableDirect Command is a table name that can get the contents of the content directly from the table.

ADCMDTEXT COMMAND is a SQL statement

ADODB event processes the constant used by subsection parameters Adstatus

Constant meaning

AdstatusCancel operation is canceled by the user

AdstusCnatdeny operations cannot reject other users access to data sources

AdStatuserRorsoccurred operations cause errors and have been delivered to the Erroors collection

Adstatusok operation success

An unpredited event is activated during the AdstatusnuNTedEvent operation

转载请注明原文地址:https://www.9cbs.com/read-29556.html

New Post(0)