Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q245367

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB245367, kbprb

↑ Back to the top

Article Info
Article ID : 245367
Revision : 3
Created on : 5/8/2003
Published on : 5/8/2003
Exists online : False
Views : 375