Step 2: Get the Data

Microsoft ActiveX Data Objects (ADO)

ADO 2.5

Step 2: Get the Data

In this step, you will write the code to open an ADO Recordset and prepare to send it to the client. Open the file XMLResponse.asp with a text editor, such as Windows Notepad, and insert the following code:

<%@ language="VBScript" %>

<!-- #include file='adovbs.inc' -->

<%
  Dim strSQL, strCon
  Dim adoRec 
  Dim adoCon 
  Dim xmlDoc 

  ' You will need to change "slqServer" below to the name of the SQL 
  ' server machine to which you want to connect.
  strCon = "Provider=sqloledb;Data Source=sqlServer;Initial Catalog=Pubs;Integrated Security=SSPI;"
  Set adoCon = server.createObject("ADODB.Connection")
  adoCon.Open strCon

  strSQL = "SELECT Title, Price FROM Titles ORDER BY Price"
  Set adoRec = Server.CreateObject("ADODB.Recordset")
  adoRec.Open strSQL, adoCon, adOpenStatic, adLockOptimistic, adCmdText

Be sure to change the value of the Data Source parameter in strCon to the name of your Microsoft SQL Server computer.

Keep the file open and go on to the next step.

Next   Step 3: Send the Data

© 1998-2003 Microsoft Corporation. All rights reserved.