Asynchronous loading is a data load method of ADO, mainly controlled by the Options parameter of the recordset!
Ado210.chm in the format: Recordset.open Source, ActiveConnection, Cursortype, LockType, Options
Options is optional. LONG value, indicating that the provider calculates the Source parameter (if this parameter indicates some of the content other than the Command object), or indicating that the Recordset should recover from the previously saved file. Can be one or more CommandTyPeenum or ExecuteOptionNum values, which can be combined with the AND operator.
ExecuteOptionNum Specifies the way the provider executes the command.
A constant value indicates that the ADASYNCEXECUTE 0x10 indicates that the command will execute asynchronously. This value cannot be combined with the value AdcmdTableDirectTyPEENUM. The AdasyncFetch 0x20 indicates that the remaining rows after the initial quantity specified in the Cachesize property will be retrieved asynchronously. AdasyncFetchnonBlocking 0x40 indicates that the main thread will never block when retrieving. If the requested row is not retrieved, the current line will move itself to the end of the file. If you open the Recordset from the Stream containing a lasting storage Recordset, AdasyncFetchnonBlocking will not work; this action will be synchronously and occurs.
When the adcmdtabledirect option is used to open Recordset, AdaSynchfetchnonBlocking does not work. The AdexecuteNorecords 0x80 indicates that the command text is a command or stored procedure that does not return row (for example, only the data is inserted). If you retrieve any rows, they will be discarded without returning. Adexecutenorecords can only be passed to the EXECUTE method for the COMMAND or Connection as an optional parameter. The result of the Adexecutestream 0x400 indicates that the command execution should be returned as a stream. AdexecuteStream can only be passed to the Execute method for the COMMAN as an optional parameter. AdexecuteRecord indicates that CommandText is a command or stored procedure, which returns a single line that should be returned as the Record object. AdoptionunSpecified -1 indicates that the command is not specified.
CommandTyPeenum Specifies how to explain the command parameters.
The constant value indicates that adcmdunspecified -1 does not specify parameters of the command type. AdcmdText 1 Calculate CommandText by a text definition called by the command or stored procedure. AdcmdTable 2 calculates CommandText by a table name, which is all returned by the internal generated SQL query. AdcmdStoredProc 4 Calculate CommandText by the stored procedure name. ADCMDunkNown 8 default. Indicates that the type of command in the CommandText property is unknown. ADCMDFILE 256 calculates CommandText by pressing the file name of the lasting Recordset. Only use with RecordSet.Open or Requory. AdcmdtableDirect 512 calculates CommandText by a table name, and the column of the table is all returned. Only use with RecordSet.Open or Requory. To use the SEEK method, you must open the Recordset by AdcmdTableDirect. This value cannot be combined with the value of ExecuteOptionNum. Generally use this parameter AdaSyncFetch to control, additional .Properties ("INITAL FETCH SIZE") = 50 can also refer to "Development of VB Distributed Application of MSCE" example, VB6.0 code:
Dim Adors as adod.recordset
set AdoRs = new ADODB.RecordsetWith AdoRs .CursorLocation = adUseClient .Properties ( "Initial Fetch Size") = 50 .Open mstrSQL, AdoCn, adOpenStatic, adLockOptimistic, adAsyncFetch If .BOF = False Or .EOF = False Then '---- ---------- Else end ifend with
Summary: A lot of netizens ask a large number of issues, and now this approach returns data. Generally 1 million data, 50 in front only 5 ~ 6 seconds will return! This way you need to pay attention to:
1. If the amount of returns is too large, and the middle is canceled, you need to use adoccn.cancel to cancel the query, otherwise the data will continue to return data.
2. If the amount of data is too large, there is a problem with the release of records. If the amount of data is 200M ~ 300M, set adors = nothing does not quickly release the cache. I hope that other netizens can provide their own insights.
3. When the amount of large data is large, the way to turn the page / grid is provided in the way, the user is extremely convenient. Some netizens provide the use of stored procedures. I combined with the data source of asynchronous load in the development process, I have implemented a good data browsing.
Development environment: VB6.0 MS SQL Server 2k Windows ADS 2K passes.