PRB: ADO Recordset That Is Persisted as XML Doesn't Save All Data If You Use Default Lock Type (303791)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6

This article was previously published under Q303791

SYMPTOMS

When you persist an ADO recordset as XML, the ADO recordset does not save the BaseCatalog, BaseTable, BaseColumn, and KeyColumn information if you use the default LockType property adLockReadOnly.

CAUSE

The BaseCatalog, BaseTable, BaseColumn, and KeyColumn information is missing because the recordset from which the XML is derived is read-only.

When you do not specify the LockType property, it defaults to adLockReadOnly, and the recordset's IRowsetUpdate and Server Cursor properties are false.

In a LockType for which the recordset is updateable, XML contains an "rs:updatable='true'" attribute along with the BaseCatalog, BaseTable, BaseColumn, and KeyColumn information.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. From the Project menu, click References, and then select the Microsoft ActiveX Data Objects 2.x Library check box.
  3. Add a CommandButton control to Form1.
  4. Paste the following code into the code window of Form1:
    Private Sub Command1_Click()
        ' Check to see if file exists.
        If Dir("C:\test.xml") <> "" Then
        Kill "C:\test.xml"
        End If
       
     Dim rsList As ADODB.Recordset
    
        Set rsList = New ADODB.Recordset
        rsList.LockType = adLockOptimistic
        rsList.ActiveConnection = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
        "Persist Security  Info=False;Initial Catalog=pubs;Data Source=JAYAPST2000"
    
        rsList.Open "Select * from Authors"
        rsList.Save "c:\test.xml", adPersistXML
        rsList.Close
        Set rsList = Nothing
    End Sub
    					
  5. Modify the ADO connection string as appropriate for your environment.
  6. Run the project, and open Test.xml in the browser. Notice that ADO has persisted the BaseCatalog, BaseTable, BaseColumn, and KeyColumn information along with the XML data.

    The Pubs database AuthorID field that has adLockOptimistic specified returns the following sample output:
    <s:AttributeType name='au_id' rs:number='1' rs:writeunknown='true' 
    rs:basecatalog='pubs' 	rs:basetable='Authors' rs:basecolumn='au_id'
    rs:keycolumn='true'> <s:datatype 	dt:type='string' rs:dbtype='str' 
    dt:maxLength='11' rs:maybenull='false'/>
    </s:AttributeType>
    					
  7. Comment out the line that sets the LockType, and run the project again.
  8. Open the XML file in the browser. Notice that the ADO has not persisted the BaseCatalog, BaseTable, BaseColumn, and KeyColumn information along with the XML data.

    The Pubs database AuthorID field that has adLockReadOnly (default) specified returns the following sample output:
    <s:AttributeType name='au_id' rs:number='1' 
    rs:writeunknown='true'><s:datatype 	dt:type='string' rs:dbtype='str' 
    dt:maxLength='11' rs:maybenull='false'/>
    </s:AttributeType>
    					

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

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


Modification Type:MajorLast Reviewed:8/7/2001
Keywords:kbDSupport kbprb KB303791