This article describes a small technique for generating XML in SQL Server 2000.
In the previous introduction of SQL2K has been mentioned in the SQL2K of XML support, using the FOR XML statement can easily translate the results of execution into an XML, which can greatly improve the efficiency of the system and development speed, the detailed content see books Online.
But the way the XML returned is accessed using ADO (Required ADO 2.6) is different from the original recordset. If you still use the recordset, you can only get an XML Schema in Unicode format without getting the content of the XML.
In fact, this problem is very easy to solve, but I think I am very familiar with ADO, did not look at help carefully, so did not find ADO is the way to get and return XML stream.
The Command object has two properties, called input stream and output stream, and the value of the property is an IUnknown interface. You can assign an XML parser interface to it, or use the request, response, etc. directly. The advantage is that there is no need to generate a recordset, save the data, and thus save the system overhead.
Here's a simple example to return XML with response:
<%@ Language=VBScript %>
<!-- #include file="ADOVBS.inc" -->
<%
Dim objConn, objCmd, i
Set objConn = Server.createobject("ADODB.CONNECTION")
objConn.Open "Provider=SQLOLEDB.1;Password=;
Persist Security Info=True;User ID=sa;Initial Catalog=PBA;Data Source=(local)"
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = objConn
objCmd.Properties("Output Stream") = Response
objCmd.Properties("XML Root") = "root"
objCmd.CommandText = "Select * from UserStatus for XML Auto"
Response.ContentType = "text/xml"
objCmd.Execute i, , adExecuteStream
Set objCmd = Nothing
objConn.Close
Set objConn = Nothing
%>