Microsoft KB Archive/277993

= FIX: ActualSize Property of the ADODB Recordset Returns -1 After Getchunk Is Called to Retrieve Data =

Article ID: 277993

Article Last Modified on 11/7/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Data Access Components 2.6

-



This article was previously published under Q277993



SYMPTOMS
The ActualSize property of the ADODB recordset returns -1 after calling the Getchunk method to retrieve data.

This problem occurs only when you use the SQLOLEDB provider that ships with MDAC 2.6 with server-side cursors. This behavior does not occur if:
 * The CursorLocation property of the recordset is set to adUseClient.
 * MDAC version 2.5 or earlier is present.
 * A different data provider is used.



RESOLUTION
Change the cursor location of the Connection object to adUseClient.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Data Access Components (MDAC) version 2.7.



Steps to Reproduce Behavior
 Create a new Visual Basic Standard EXE project. Form1 is created by default. On the Project menu, select References, and then set a Reference to Microsoft ActiveX Objects 2.6.  Paste the following code into the Form1 code window:

Note Make sure that the User ID has the appropriate permissions to perform this operation on the database. Private Sub Form_Load

Dim cn As ADODB.Connection Dim rec As ADODB.Recordset

Set cn = New ADODB.Connection 'cn.CursorLocation = adUseClient cn.Open &quot;Provider=SQLOLEDB.1;Persist Security Info=False;User ID= ;password= ;Initial Catalog=pubs;Data Source=TestServer&quot;

Set rec = New ADODB.Recordset rec.Open &quot;select * from pub_info&quot;, cn, adOpenKeyset, adLockBatchOptimistic, -1 Dim varChunk As Variant MsgBox &quot;Before &quot; + Str(rec.Fields.Item(&quot;logo&quot;).ActualSize) varChunk = rec.Fields.Item(&quot;logo&quot;).GetChunk(rec.Fields.Item(&quot;logo&quot;).ActualSize) MsgBox &quot;After &quot; + Str(rec.Fields.Item(&quot;logo&quot;).ActualSize)

End Sub  Make the appropriate changes in the cn.Open statement to supply the required connection parameters to connect to SQL Server. Run the project.

Results: The second message box displays a &quot;-1.&quot; Stop the project, and uncomment the code line &quot;cn.CursorLocation = adUseClient.&quot;</li> Restart the project.

Results: The second message box is the same as the first, which is correct.</li></ol>

Keywords: kbbug kbfix KB277993

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.