This sample requires the client to connect to a SQL Server
2000 server by using the Microsoft OLE DB Provider for SQL Server that ships
with Microsoft Data Access Components (MDAC) version 2.6 or later only. Prior
versions of SQL Server always returned data in some form of a recordset as a
result of executing a 'SELECT..' SQL statement. In SQL Server 2000, the 'SELECT
...' SQL Statement has been enhanced to include a new
FOR XML clause, frequently called an SQL XML query. This clause allows
SQL Server to return data in the form of an XML document.
In
addition, the ADO
Command object has been enhanced to configure and retrieve XML data as a
result of executing "SELECT ... FOR XML" SQL queries.
XMLStream.exe
provides an example that does the following:
- Sets up the connection to a SQL Server 2000 database:
_bstr_t m_Conn("PROVIDER=SQLOLEDB.1;Server=SQL2000Srv;Database=Northwind;uid=sa;pwd=;");
- Sets up the SQL XML query:
_bstr_t m_Qry("<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>
<sql:query>SELECT * FROM PRODUCTS FOR XML AUTO</sql:query>
</ROOT>");
- Configures the input Stream object to contain the SQL XML query:
hr = strm->Open(vtEmpty,adModeUnknown,adOpenStreamUnspecified,L"",L"");
hr = strm->WriteText(m_Qry,adWriteChar);
- Sets the CommandStream property of the ADO Command object to the input Stream:
hr = cmd->putref_CommandStream(strm);
- Assigns the SQL XML globally unique identifier (GUID) to
the Dialect property of the Command object:
NOTE: Dialect defines the syntax and general rules that the provider uses to
parse the string or stream. Setting the command language dialect specifies how
the Microsoft OLE DB Provider for SQL Server interprets the command text that
is received from ADO.
hr = cmd->put_Dialect(_bstr_t("{5D531CB2-E6Ed-11D2-B252-00C04F681B71}"));
- Sets up an output Stream to retrieve the XML data:
hr = cmd->Properties->Item[L"Output Stream"]->put_Value(_variant_t((IDispatch*) outStrm));
- Executes the Command by using the adExecuteStream enumeration:
hr = cmd->Execute(&vra,&vtEmpty,adExecuteStream);
Steps to Run the Sample
- Unzip XMLStream.exe.
- Create an empty Win32 console application.
- Insert the XMLStream.cpp file into the project.
- Modify the connection string to refer to a valid SQL Server
2000 database.
- From the Project menu, click Settings, and then click the C/C++ tab. In the Project Options box, change /MLd to /MTd.
- Compile and then run the application.
The
following file is available for download from the Microsoft Download
Center:
Release Date:
September 27, 2000
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 XMLStream.exe file contains the following files:
Collapse this tableExpand this table
File name | Size |
---|
EULA.txt | 2 KB |
XMLStream.cpp | 6 KB |