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



The information in this article applies to:

  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.1 (GA)
  • Microsoft Data Access Components 2.1 SP1
  • Microsoft Data Access Components 2.1 SP2
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7

This article was previously published under Q245367

SYMPTOMS

When you try 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.
  2. Add a reference to the Microsoft ActiveX Data Objects 2.x Library.
  3. Double-click Form1. Copy and paste the following code under the Form_Load() event:
      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.

Modification Type:MajorLast Reviewed:5/8/2003
Keywords:kbprb KB245367