Microsoft KB Archive/193871

= INFO: Passing ADO Recordsets in Visual Basic Procedures =

Article ID: 193871

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q193871



SUMMARY
This article describes the expected behavior when passing ActiveX Data Objects (ADO) recordset objects in Visual Basic procedures. The behavior depends on a number of factors including the value of the CursorLocation property, whether you pass the recordset in process or out of process, and whether you pass the recordset ByRef or ByVal.



In Process
If you pass an ADO recordset in process, you are passing a reference to an object in memory regardless of whether you attempt to pass the recordset variable ByRef or ByVal and regardless of the setting of the CursorLocation property.

Out Of Process
When you pass an ADO recordset out of process, the ADO libraries are loaded in both processes. The ADO libraries pass the information stored in the recordset from the one process to the other. Each process now has its own copy of the recordset object rather than a reference to the initial object.

The bookmark, filter, and sort information are not used in determining what records to pass across process boundaries. All rows of the recordset are passed, regardless of the current setting of the Filter property. In the resulting recordset, the first record is the current record regardless of the bookmark set in the other process. The resulting recordset does not receive the value of the Sort property from the other process.

The MarshalOptions property can be used to control whether the whole Recordset or only the modified rows are marshalled.

If you pass the variable ByRef, the data for the recordset is passed back to the calling procedure. This can cause an unnecessary performance hit and should be avoided whenever possible. Unless you want the changes made within the procedure to be returned to the calling procedure, do not pass the recordset ByRef. Keep in mind that if you set MarshalOptions to adMarshalModifiedOnly and pass the recordset ByRef, that at the end of the call to the server the client has a recordset that contains only the modified rows.

If you pass the variable ByVal, then the recordset is not returned from the procedure. This means that your recordset remains in the same state as it was before the call to the procedure. The modified rows are still marked as having been modified.

You can only pass an ADO recordset out of process if it's CursorLocation is adUseClient. You should also set the recordset's ActiveConnection property to Nothing before passing it out of process.

Keywords: kbinfo KB193871

-

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

© Microsoft Corporation. All rights reserved.