The
following file is available for download from the Microsoft Download
Center:
Release Date:
Oct-11-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 OLEDBSQLXML.exe file contains the following files:
Collapse this tableExpand this table
File name | Size |
---|
EULA.txt | 2 KB |
OLEDBSQLXML.cpp | 4 KB |
This sample requires the client to connect to a SQL
Server 2000 Server using the Microsoft SQL Server OLE DB Provider (SQLOLEDB)
that ships with Microsoft Data Access Components (MDAC) version 2.6 or later.
Prior versions of SQL Server always returned data in the some form of 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 a SQL XML query. This clause allows SQL
Server to return data in the form of an XML document.
In the
SQLOLEDB provider that ships with MDAC 2.6, the
ICommand::Execute method has been enhanced to return XML data using an
ISequentialStream interface instead of
IRowset. The SQL XML query can be executed by setting up the
ICommandStream interface to contain the SQL XML query or by passing the query to
the
ICommandText::SetCommandText method. The sample does this as follows:
- Sets up the SQL XML query:
m_szCommand = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>
<sql:query>SELECT PRODUCTID, PRODUCTNAME FROM PRODUCTS WHERE PRODUCTNAME LIKE 'C%' FOR XML AUTO </sql:query>
</ROOT>";
- Sets the ICommandText interface to contain the SQL XML query set its dialect to
DBGUID_MSSQLXML,
if(FAILED(hr = m_spCommand->QueryInterface(&pCommandText)))
{
printf("Failed to get an ICommandStream interface...\n");
return hr;
}
if(FAILED(hr = pCommandText->SetCommandText(DBGUID_MSSQLXML, T2COLE((LPCTSTR)m_szCommand))))
{
printf("Failed to set command stream.\n");
return hr;
}
- Sets up an output stream to retrieve the XML data and
execute the command:
m_spCommand->Execute(NULL, IID_ISequentialStream, NULL, NULL, (IUnknown **) &pIXMLOutput );
- Executes the ADO Command using the adExecuteStream enumeration:
hr = cmd->Execute(&vra,&vtEmpty,adExecuteStream);
Steps to Run the Sample
- Create an empty Win32 console application.
- Insert OLEDBSQLXML.cpp into the project.
- Ensure that the project is built with the SQLOLEDB.H header file that ships with the MDAC 2.6 Software Development Kit
(SDK).
- Modify the connection string to connect to a valid SQL
Server 2000 database.
- Compile and then run the application.