PRB: ADO Recordset Open Method May Behave Synchronously Even if adAsyncFetch is SpecifiedID: Q224332
|
You may see the following symptoms, even though you've specified adAsyncFetch:
When a recordset is opened with adAsyncFetch, only those records that are not returned during the initial fetch of records are asynchronously retrieved. If all of the records are returned in the initial fetch, no asynchronous fetching occurs, and the FetchComplete event is never raised.
Set the recordset's "Initial Fetch Size" property to a low value, such as 1.
This behavior is by design.
When you specify adAsyncFetch, 50 rows are fetched by default in the first batch of records. However, you can control the number of records in the initial fetch by setting the "Initial Fetch Size" property in the ADO Recordset Properties collection.
You must set the "Initial Fetch Size" property after the ADO recordset object is created, but before the recordset is opened. Also, because asynchronous fetching requires client-size cursors, be sure to set "Initial Fetch Size" after the code to set the recordset's CursorLocation to adUseClient.
'rst.Properties("Initial Fetch Size") = 1
Private WithEvents rst As ADODB.Recordset
Private Sub Form_Load()
Dim strCnn As String
strCnn = "Provider=SQLOLEDB;Data Source=MyServer;Initial Catalog=Pubs;User ID=sa;Password="
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
'Uncomment the next line to workaround the problem
'rst.Properties("Initial Fetch Size") = 1
rst.Open "select * from publishers", strCnn, adOpenKeyset, adLockOptimistic, adAsyncFetch
rst.MoveLast
End Sub
Private Sub rst_FetchComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
MsgBox "FetchComplete executed"
End Sub
For more information on the Initial Fetch Size property, please refer to the example provided in the following article:
"What's New in ADO 2.0."
For additional information on the adAsyncFetch flag, please refer to the Microsoft ADO Programmer's Reference, under "Open Method (ADO Recordset)."
Additional query words:
Keywords : kbADO kbDatabase kbGrpVBDB
Version : WINDOWS:2.0,2.01,2.1
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 12, 1999