Microsoft KB Archive/303791

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

Article ID: 303791

Article Last Modified on 8/7/2001

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 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 &quot;rs:updatable='true'&quot; attribute along with the BaseCatalog, BaseTable, BaseColumn, and KeyColumn information.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Form1 is created by default. From the Project menu, click References, and then select the Microsoft ActiveX Data Objects 2.x Library check box. Add a CommandButton control to Form1.  Paste the following code into the code window of Form1: Private Sub Command1_Click ' Check to see if file exists. If Dir(&quot;C:\test.xml&quot;) <> &quot;&quot; Then Kill &quot;C:\test.xml&quot; End If Dim rsList As ADODB.Recordset

Set rsList = New ADODB.Recordset rsList.LockType = adLockOptimistic rsList.ActiveConnection = &quot;Provider=SQLOLEDB.1;Integrated Security=SSPI;&quot; & _ &quot;Persist Security Info=False;Initial Catalog=pubs;Data Source=JAYAPST2000&quot;

rsList.Open &quot;Select * from Authors&quot; rsList.Save &quot;c:\test.xml&quot;, adPersistXML rsList.Close Set rsList = Nothing End Sub  Modify the ADO connection string as appropriate for your environment.  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> </li> Comment out the line that sets the LockType, and run the project again.</li>  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> </li></ol>

<div class="references_section">