Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 264869 - Last Review: November 7, 2003 - Revision: 3.0
PRB: Persisting XML Directly into DOM Causes Run-Time Error '438'
This article was previously published under Q264869
On This Page
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.
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Â
(http://kbalertz.com/Feedback.aspx?kbNumber=305019/EN-US/
)
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 = "Provider=MSDASQL;Data Source=<YOUR ODBC DSN>;User Id=<username>;Password=<strong password>;Initial Catalog=pubs"
SQL = "SELECT * FROM AUTHORS"
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
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 "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.
-or-
- You set a project reference to version 2.1 of the Microsoft ActiveX Data Objects Library.
APPLIES TO
- Microsoft XML Parser 2.0
- Microsoft XML Parser 2.5
- Microsoft XML Parser 3.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 ActiveX Data Objects 2.1
- Microsoft ActiveX Data Objects 2.1 Service Pack 1
- Microsoft ActiveX Data Objects 2.1 Service Pack 2
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please