In IIS 5.0 (available with Windows® 2000 Server), ADO Recordset objects can be directly persisted to or from the ASP response and request objects. Use ASP on Web servers to dynamically generate XML from ADO Recordsets. The following example shows how this can be done:
<%@ codepage="65001" %> <object id="rstCustomers" progid="ADODB.Recordset" runat="Server"></object> <!--metadata name="Microsoft ActiveX Data Objects 2.5 Library" type="TypeLib" uuid="{00000205-0000-0010-8000-00AA006D2EA4}"--> <% Option Explicit Dim strSQL, strConnection Response.ContentType = "text/xml" strSQL = "SELECT CustomerID, CompanyName, ContactName FROM Customers ORDER By CompanyName" strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("NWind.mdb") rstCustomers.CursorLocation = adUseClient rstCustomers.Open strSQL, strConnection, adOpenStatic, adLockOptimistic Response.Write "<?xml version="1.0" encoding="ISO-8859-1"?>" & vbCRLF rstCustomers.save response, adPersistXML rstCustomers.Close %>
As shown, the Recordset can be directly saved to the ASP response object, thereby avoiding any expensive disk I/O operations. When this ASP page is opened in a user's browser, the XML representing the ADO Recordset is sent and displayed directly in the browser. ASP has extended its response object to expose an IStream interface directly over the buffered stream.