PRB: Bookmarks Are Not Persisted or Marshalled (191084)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1 SP2
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q191084

SYMPTOMS

After a recordset has been reopened, once persisted to disk or marshalled across processes or computer boundaries, the bookmarks are no longer correct and they appear to be reset.

CAUSE

Bookmarks are not preserved when a recordset is persisted to a file with the Save method or when marshalled across processes or computer boundaries.

STATUS

This behavior is by design.

MORE INFORMATION

NOTE: This sample code was written for ADO 2.0 and later. ADO 1.5 does not support a Save method.

Steps to Reproduce Behavior

  1. Start Visual Basic.
  2. Add a project reference to the Microsoft ActiveX Data Objects Library.
  3. Paste the following code in the default forms Load method:
          Dim oRs As ADODB.Recordset      
          Set oRs = New ADODB.Recordset
    
          With oRs
           .CursorLocation = adUseClient
           .CursorType = adOpenStatic
           .LockType = adLockBatchOptimistic
           .Fields.Append "c_col1", adChar, 2
           .Fields.Append "c_col2", adChar, 2
           .Open
          End With
    
          oRs.AddNew
          oRs(0) = "1"
          oRs.Update
          oRs.AddNew
          oRs(0) = "2"
          oRs.Update
          oRs.AddNew
          oRs(0) = "3"
          oRs.Update
          oRs.MoveFirst
    
          Debug.Print oRs.RecordCount
          Debug.Print oRs.Bookmark
    
          'Delete the first row, move to the new first row, and check its book
          'mark value.
          oRs.Delete
          oRs.MoveFirst
          Debug.Print oRs.Bookmark
    
          'The Save method can not overwrite existing files.
          On Error Resume Next
          Kill "C:\mytmp.txt"
          On Error GoTo 0
    
          oRs.Save "C:\mytmp.txt"
          oRs.Close
          Set oRs = Nothing
    
          'Re-open persisted file and check the first row's bookmark.
          'Prior to persisting the recordset the first row's bookmark was a 2.
    
          Set oRs = New ADODB.Recordset
          oRs.Source = "C:\mytmp.txt"
          oRs.Open
          oRs.MoveFirst
          Debug.Print oRs.Bookmark
          Debug.Print oRs.RecordCount
          Debug.Print oRs(0)
    
          Unload Me
    					
  4. From the View menu, choose Immediate Window.
  5. Press the F8 key repeatedly to step through the code.

REFERENCES

For additional information about ADO Recordset Properties, please see the following article in the Microsoft Knowledge Base:

185423 Most ADO Recordset Properties are not Marshalled


Modification Type:MinorLast Reviewed:3/2/2005
Keywords:kbDatabase kbDSupport kbprb KB191084