Microsoft KB Archive/264869

= PRB: Persisting XML Directly into DOM Causes Run-Time Error '438' =

Article ID: 264869

Article Last Modified on 11/7/2003

-

APPLIES TO


 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0
 * Microsoft Data Access Components 2.1
 * Microsoft Data Access Components 2.1 Service Pack 2
 * Microsoft Data Access Components 2.1 Service Pack 1
 * Microsoft Data Access Components 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2

-



This article was previously published under Q264869



SYMPTOMS
With Microsoft Data Access Components (MDAC) version 2.1 and later, the ADO Recordset object supports the feature to persist an ADO recordset in XML format to a file on the disk by using the Save method of the ADO Recordset object. This data can then be loaded into the Microsoft XML Document Object Model (DOM) from the persisted file.

MDAC 2.5 and later has a feature that saves the ADO recordset directly into the DOM without having to save the data in XML format to a file on disk first. If you try to persist the ADO recordset as XML data directly into the DOM using MDAC 2.1, you receive the following error message:

Run-time error '438'

Object doesn't support this property or method



CAUSE
Persisting the ADO Recordset directly into an XML DOMDocument object utilizes the ADO Stream object. The Stream object is an ADO object introduced in ADO 2.5. It does not exist in ADO 2.1, ADO 2.1 SP1, and SP2. Versions of ADO earlier than 2.1 do not support XML persistence.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
The following Visual Basic code sample demonstrates how to load an MSXML DOMDocument object directly by using the Save method of the ADO Recordset object. This example uses data from the SQL Server Pubs sample database. The preceding error message occurs if this code is run on a computer with a version of MDAC earlier than MDAC 2.5, or by referencing version 2.1 of the ActiveX Data Objects Library.

If a newer version of MSXML has been installed in side-by-side mode, you must explicitly use the Globally Unique Identifiers (GUIDs) or ProgIDs for that version to run the sample code. For example, MSXML version 4.0 can only be installed in side-by-side mode. For additional information about the code changes that are required to run the sample code with the MSXML 4.0 parser, click the following article number to view the article in the Microsoft Knowledge Base:

305019 INFO: MSXML 4.0 Specific GUIDs and ProgIds

To run this code, follow these steps:  Create a new Visual Basic Standard EXE project. Form1 is created by default. On the Project menu, click to select References, and then click to add references to Microsoft ActiveX Data Objects version and Microsoft XML version 2.0 or later.  Paste the following code into the code area of the Form1 module. You must modify the database connection string and the query so that it works for your specific database. Make sure that the User ID has the appropriate permissions to perform this operation on the database. Private Sub Form_Load Dim szConnect As String Dim SQL As String szConnect = &quot;Provider=MSDASQL;Data Source=;User Id= ;Password= ;Initial Catalog=pubs&quot; SQL = &quot;SELECT * FROM AUTHORS&quot; Dim oRS As ADODB.Recordset Dim oCN As ADODB.Connection Set oCN = New ADODB.Connection Set oRS = New ADODB.Recordset With oCN .CursorLocation = adUseClient .ConnectionString = szConnect .ConnectionTimeout = 5 .Open szConnect End With oRS.Open SQL, oCN Dim xmlDoc As DOMDocument Set xmlDoc = New DOMDocument

' To specify a specific version, use a declaration like the following, with the appropriate version in the ProgID: ' Dim xmlDoc As MSXML2.DOMDocument40 ' Set xmlDoc = New MSXML2.DOMDocument40 xmlDoc.async = False oRS.Save xmlDoc, adPersistXML If xmlDoc.parseError.errorCode <> 0 Then MsgBox &quot;Errors During Load&quot; & vbCrLf & xmlDoc.parseError.errorCode & xmlDoc.parseError.reason Else MsgBox xmlDoc.xml End If   oRS.Close oCN.Close Set oRS = Nothing Set oCN = Nothing End Sub  Run the project. If a project reference has been set to version 2.5 or later of the ActiveX Data Objects Library, then the XML persisted to the DOMDocument is displayed in a message box indicating that it has successfully loaded into the DOM.

The error message in the &quot;Symptoms&quot; section of this article is raised if:  You run this code on a computer that does not have MDAC 2.5 or later installed.

-or-

</li> You set a project reference to version 2.1 of the Microsoft ActiveX Data Objects Library.</li></ul> </li></ol>

Additional query words: 438

Keywords: kbprb KB264869

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.