PRB: Updating ADO Recordset Persisted from Read-Only Cursor May Fail

ID: Q245367


The information in this article applies to:
  • Microsoft Data Access Components versions 2.1, 2.1 (GA), 2.1 SP1, 2.1 SP2, 2.5


SYMPTOMS

When attempting to update a persisted ADO recordset from a read-only cursor, the following error appears:

Run-time error '-2147467259 (80004005)':
Insufficient base table information for updating or refreshing.


CAUSE

In ADO 2.0 and later, you can use the SAVE method on a recordset object to persist recordsets to local storage and reload them later. For optimization purposes, when a read-only recordset is persisted, ADO does not set the Unique Rows property on the provider. That is, no base table information is persisted. An update error occurs when you try to update a recordset due to lack of base table information.


RESOLUTION

Before updating a recordset that has been persisted, make sure that it was opened and persisted with attributes that allow updating. See the "More Information" section for sample code.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Standard EXE project in Visual Basic. Form1 is created by default. Reference the Microsoft ActiveX Data Objects 2.5 Library or earlier.


  2. Double-click Form1. Copy and paste the following code under the Form_Load() event:


  3. 
      Dim rs1 As New Recordset
      Dim rs2 As New Recordset
      Dim cn As New Connection
      
      cn.CursorLocation = adUseClient
    
      cn.Open "Provider=SQLOLEDB;Data Source=MyServer;Initial Catalog=Pubs;User ID=sa;Password=;"
      On Error Resume Next
      cn.Execute "Drop Table T1"
         cn.Execute "CREATE TABLE T1 (K1 Int PRIMARY KEY, F2 Int)"
      On Error GoTo 0
      cn.Execute "INSERT INTO T1 VALUES(0, 100)"
      
      rs1.Open "Select K1, F2 From T1", cn, adOpenForwardOnly, adLockReadOnly
    
      'Commenting the above line and uncommenting the next line will not generate the error.
      'rs1.Open "Select K1, F2 From T1", cn, adOpenKeyset, adLockOptimistic
      
      If Dir("Persist.xml") <> "" Then Kill "Persist.xml"
      rs1.Save "Persist.xml", adPersistXML
    
      rs2.Open "Persist.xml", cn, adOpenKeyset, adLockBatchOptimistic, adCmdFile
    
      rs2.AddNew
      rs2("K1") = 1
      rs2("F2") = "200"
      rs2.UpdateBatch  'Error occurs here 
  4. Run the project and note the error.


  5. Modify the code as described in the comments line and re-run the project.


© Microsoft Corporation 2000, All Rights Reserved.
Contributions by Adrian C. Bradley, Microsoft Corporation

Additional query words:

Keywords : kbADO kbGrpVBDB kbGrpMDAC kbDSupport kbMDAC250 kbADO250
Version : WINDOWS:2.1,2.1 (GA),2.1 SP1,2.1 SP2,2.5
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: January 17, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.