Skip to content

Latest commit

 

History

History
62 lines (52 loc) · 2.62 KB

File metadata and controls

62 lines (52 loc) · 2.62 KB
title Executing SQL Queries (SQLXMLOLEDB Provider) | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql-server-2016
ms.reviewer
ms.suite
ms.technology
dbe-xml
ms.tgt_pltfrm
ms.topic reference
helpviewer_keywords
queries [SQLXML], SQLXMLOLEDB Provider
xml root property [SQLXML]
SQLXMLOLEDB Provider, executing SQL queries
SQL queries [SQLXML]
ms.assetid 50334cf5-9c87-4c00-9beb-e08577c4fa82
caps.latest.revision 28
author douglaslMS
ms.author douglasl
manager jhubbard

Executing SQL Queries (SQLXMLOLEDB Provider)

This example illustrates the use of the following SQLXMLOLEDB Provider-specific properties:

  • ClientSideXML

  • xml root

In this client-side ADO sample application, a simple SQL query is executed on the client. Because the ClientSideXML property is set to True, the SELECT statement without the FOR XML clause is sent to the server. The server executes the query and returns a rowset to the client. The client then applies the FOR XML transformation to the rowset and produces an XML document.

The xml root property provides the single top-level root element for the XML document that is generated.

Note

In the code, you must provide the name of the instance of Microsoft [!INCLUDEssNoVersion] in the connection string. Also, this example specifies the use of the [!INCLUDEssNoVersion] Native Client (SQLNCLI11) for the data provider, which requires additional network client software to be installed. For more information, see System Requirements for SQL Server Native Client.

Option Explicit  
Sub main()  
Dim oTestStream As New ADODB.Stream  
Dim oTestConnection As New ADODB.Connection  
Dim oTestCommand As New ADODB.Command  
  
oTestConnection.Open "provider=SQLXMLOLEDB.4.0;data provider=SQLNCLI11;data source=SqlServerName;initial catalog=AdventureWorks;Integrated Security=SSPI ;"  
oTestCommand.ActiveConnection = oTestConnection  
oTestCommand.Properties("ClientSideXML") = True  
oTestCommand.CommandText = "SELECT TOP 10 FirstName, LastName FROM Person.Contact FOR XML AUTO"  
oTestStream.Open  
oTestCommand.Properties("Output Stream").Value = oTestStream  
oTestCommand.Properties("xml root") = "root"  
oTestCommand.Execute , , adExecuteStream  
  
oTestStream.Position = 0  
oTestStream.Charset = "utf-8"  
Debug.Print oTestStream.ReadText(adReadAll)  
End Sub  
Sub Form_Load()  
 main  
End Sub