ADO, ASP and XML - 15 Nov 2001

Description This sample shows how you can generate XML data from an ADO recordset. We programmatically create an ADO recordset object on the web server in response to parameters that the user selects. The client portion of the application implements a simple user interface that collects the parameters required to create the ADO recordset object. More Details The client user interface code is contained in the sample1.htm file. It collects three parameters from the user: the computer that your SQL Server database resides on, the database to use, and the SQL query to execute against the database. A good choice would be to use the standard pubs standard database and the ubiquitous select * from titles query. There are two server-side Active Server Page (ASP) files that can be called from the client. The runQuery.asp file contains the VBScript version of the code and the runQueryJ.asp file contains the JavaScript version of the code. You can choose which page is called by changing the action attribute of the HTML

element in sample1.htm. When you click on the Submit button at the bottom of the sample1.htm page, Internet Explorer will collect the parameters entered into the user interface and transmits them to the server as part of an HTTP POST request. The ASP page retrieves those parameters by inspecting the expando properties of the Request object (expando properties are accessed through the default Items property / collection of the Request object: e.g. Request( txtSQL ) ). The ASP script generates an OLE DB connection string using the txtComputer and txtDatabase expando properties (if you want to use a database other than SQL Server, you can modify the OLE DB string generation code in the ASP page). The ASP page uses these parameters to create an ADO recordset object. Once the recordset object has been created, ADO lets you save the contents of the recordset in an XML format. There are two ways to stream the contents of the ADO recordset object back to the client. Which way that can be used depends on the version of Internet Information Server that you are using. The code in the ASP pages in this sample application use the version number of IIS to determine which code path to execute. If you are using IIS 4.0 and MDAC 2.1, the ADO runtime only supports saving ADO recordsets to a file in XML format. In these cases, we create a temporary XML file on disk and we use the IIS FileSystemObject and Response objects to read and stream the XML data back to the client. If you are using IIS 5.0 and MDAC 2.5, the ADO runtime allows you to save ADO recordsets directly to the Response object in XML format. The Save method of the ADO recordset object in ADO 2.5 allows you to pass an object reference as the first parameter (in ADO 2.1, this parameter was typed as a string). The actual streaming is accomplished under the covers using the IStream interface that is implemented only by the Response and Request objects of IIS 5.0. Note that this sample must be manually copied to your web server. You can find the files that you need to copy in the ADOXML\ADOXML_Local subdirectory. To copy the source files to the web server, run the setup.cmd script in the ADOXML subdirectory. You must have the Windows Scripting Host installed to run this setup script. Browser/Platform Compatibility This sample requires Internet Explorer 5.0 on the client, and Internet Information Server 4.0 on the server. The Microsoft Data Access Components SDK Version 2.5 must be installed on the server. If you are running Windows 2000, the ASP scripts on the server will conditionally execute a different code path to take advantage of new features that are only available in the Microsoft Data Access Components SDK Version 2.5 and Internet Information Server 5.0. Usage To install the sample, run the Setup.cmd file. This in turn invokes the Setup.js file, which creates a virtual directory for the application on your Web server. To run the sample, open the browser and navigate to http://localhost/adoxml/adoxml.htm.

Complete Article

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.