Microsoft KB Archive/271775

= SAMPLE: How To Retrieve Relational Data Using OpenXML with ADO in Visual C++ =

Article ID: 271775

Article Last Modified on 8/9/2004

-

APPLIES TO


 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q271775



SUMMARY
OpenXML.exe demonstrates how to retrieve an ADO Recordset from an input XML document by using the OpenXML feature in SQL Server 2000.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

OpenXML.exe

Release Date: 10-19-2001

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The OpenXML.exe file contains the following files:

OpenXML.exe is a SQL Server 2000 extension to Transact-SQL that allows stored procedures to process XML and generate rowsets from the data for use by Transact-SQL statements. In this sample, an ADO client passes an XML document to a stored procedure. The stored procedure runs a SELECT statement, which generates a rowset. This rowset is then returned to the client as an ADO Recordset.

This sample creates a stored procedure named SP_OpenXML_Example on a SQL Server 2000 database and passes an XML document XMLDoc.xml to the stored procedure. The stored procedure processes the document using OpenXML and returns an ADO Recordset back to the client.

Additionally, the SP_OpenXML_Example stored procedure contains calls into the system stored procedures sp_xml_preparedocument and sp_xml_removedocument that load and unload the document from memory respectively. The SP_OpenXML_Example stored procedure is doing the following things:


 * 1) Runs the sp_xml_preparedocument system stored procedure to prepare the XML document for use by Transact-SQL statements.
 * 2) Uses the OpenXML-generated rowset in a query.
 * 3) Runs sp_xml_removedocument to remove the prepared XML document from memory.

For more details about the sp_xml_preparedocument and sp_xml_removedocument stored procedures or about OpenXML, refer to SQL Server 2000 Books OnLine.

Steps to Run the Sample

 * 1) Create an empty Win32 console application.
 * 2) Insert OpenXML.cpp into the project.
 * 3) From the Project menu, click Settings, and then click the C/C++ tab. In the Project Options dialog box, change /MLd to /MTd.
 * 4) Copy XMLDoc.xml into the project folder.
 * 5) Compile and then run the application.

