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: Persisting XML Directly into DOM Causes Run-Time Error '438'

View products that this article applies to.

This article was previously published under Q264869

↑ Back to the top


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

↑ Back to the top


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.

↑ Back to the top


This behavior is by design.

↑ Back to the top

More information

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:
  1. Create a new Visual Basic Standard EXE project. Form1 is created by default.
  2. 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.
  3. 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 = "Provider=MSDASQL;Data Source=<YOUR ODBC DSN>;User Id=<username>;Password=<strong password>;Initial Catalog=pubs"
        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 "Errors During Load" & vbCrLf & xmlDoc.parseError.errorCode & xmlDoc.parseError.reason
            MsgBox xmlDoc.xml
        End If
        Set oRS = Nothing
        Set oCN = Nothing
    End Sub
  4. 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 "Symptoms" section of this article is raised if:
    • You run this code on a computer that does not have MDAC 2.5 or later installed.


    • You set a project reference to version 2.1 of the Microsoft ActiveX Data Objects Library.

↑ Back to the top

Keywords: kbprb, KB264869

↑ Back to the top

Article Info
Article ID : 264869
Revision : 4
Created on : 11/7/2003
Published on : 11/7/2003
Exists online : False
Views : 403