Microsoft KB Archive/151815

= BUG: RDO Rowcount May Be Wrong When Using rdAsyncEnable Flag =

Article ID: 151815

Article Last Modified on 7/14/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q151815



SYMPTOMS
When using rdoResultsets, the RowCount property is useful for determining how many records have been returned by the query. Depending on the driver and data source, the RowCount property returns either -1 to indicate that the number of rows is not available, or 0 to indicate that no rows were returned by the rdoResultset. If the driver is capable of returning a row count, the RowCount property returns the number of rows in the rdoResultset.

When opening an rdoResultset using the rdAsyncEnable flag, the RowCount will always return 0. This could lead to the mistaken assumption that the query returned no records.



WORKAROUND
If a Movelast is executed against the rdResultset before the RowCount is queried, then the RowCount will be correctly set.

If the rdAsyncEnable flag is not passed to OpenResultset, the problem does not occur.



STATUS
Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this issue and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
The following Visual Basic code opens a connection to the server and creates an asynchronous rdoResultset. This code uses a "DSN-less" ODBC connection so you do not need to set up a DSN (Data Source Name) with the ODBC Admin utility.

For more details on doing this DSN-less connection, see the following article in the Microsoft Knowledge Base:

147875 : How to Use DSN-Less ODBC Connections with RDO and DAO

In the following code, MyServer is assumed to be a Microsoft SQL Server with the default database PUBS installed.

Steps to Reproduce Problem
 Start the 32-bit Edition of Visual Basic version 4.0 for Windows. Form1 is created by default. Add a single Command button to the form.  Add the following code to the Command1 Click Event.

Note You must to change Username= and PWD = to the correct values before you run this code. Make sure that Username has the appropriate permissions to perform this operation on the database. Private Sub Command1_Click Dim rdoConn As rdoConnection Dim rdoRes As rdoResultset Dim tempStr As String

Set rdoConn = rdoEnvironments(0).OpenConnection("", _                                   rdDriverNoPrompt, _                                    False, "DRIVER={SQL Server};" & _                                    "SERVER=MySQLServer;DATABASE=pubs;" & _                                    "Username= ;PWD= ;")

Set rdoRes = rdoConn.OpenResultset("select * from authors", _                                        rdOpenKeyset, rdConcurLock, _                                         rdAsyncEnable)

While rdoRes.StillExecuting DoEvents Wend Debug.Print rdoRes.RowCount rdoRes.Close rdoConn.Close

End Sub

 From the File menu, select Save. Press the F5 key, or click Start on the Run menu to run the application. Click on Command1 and note that in the debug window the number 0 appears.</ol>

<div class="references_section">