Using ’s ActiveX Data Objects with the ASP Reports Server

Troubleshooting ADO Issues

Overview

This white paper discusses the issues that could arise when attempting to display reports using and ActiveX Data Objects (ADO). It will address these issues and suggest troubleshooting techniques. Contents

INTRODUCTION ...... 1 SET THE CORRECT SESSION VARIABLES ...... 2 CHECK YOUR VERSION OF P2SMON.DLL ...... 2 CHECK YOUR RECORD SET...... 2 CHECK YOUR REPORT...... 5 STILL HAVING TROUBLE?...... 6 FINDING MORE INFORMATION...... 7 CONTACTING CRYSTAL DECISIONS FOR TECHNICAL SUPPORT ...... 8

Introduction

Microsoft’s ActiveX Data Objects (ADO) is an Active Server Pages (ASP) component that helps you connect your directly to your web server, by providing a high-level language wrapper around an OLE database.

The main purpose of ADO is to access and manipulate your data while reducing network traffic and increasing performance. Crystal Reports handles the designing and reporting functions.

When using Crystal Reports with ActiveX Data Objects, the Crystal Reports Viewer may not display the requested report, or the following error messages may occur:

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 1 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

• “An Error has occurred on the server in accessing the following data source” • “User Session has Expired.”

The following sections will help you troubleshoot Crystal Reports for ADO ASP.

Set the correct session variables

Ensure that the ADO, Remote Data Object (RDO) or Crystal Data Object (CDO) record set is a session variable. If the record set is not a session variable you may receive the error “Object does not Support this Property or Method” on the SetPrivateData function call. The Rptserver.asp also will not be able to access it as these variable names are hard coded into it. The line of code referencing this should resemble the following:

Table1.SetPrivateData 3, session("oRs")

NOTE Remember, when storing a connection in a session variable, connection pooling is not possible. This is because the connection object will not be freed up to join the pool until the session is over as it is only meant to work for the user for which the session was created.

Check your version of P2smon.dll

Crystal Reports provides a 32-bit Active Data driver called P2smon.dll (Pdsmon.dll is the 16 bit version), which is necessary for the creation of data definition files. It also provides two functions that can make the creation of reports based on ADO record sets easier by creating a .TTX file based on the result set. For more information, see “Active Data Driver Functions” in Crystal Reports Developer’s Help.

Ensure that you are using the most recent version of P2smon.dll. For Active Data in ASP, the version must be at least 6.0.0.15 or later It is also very important to know the version of the P2smon.dll with which the report was created. Any version of P2smon.dll before 6.0.0.15 will give the error “Object does not Support this Property or Method” on the SetPrivateData function call.

The original P2smon.dll wrote the database definition (.TTX file structure) to the .rpt file, where later versions do not. If the report was created with a version of P2smon.dll prior to 6.0.0.15 you may need to re-create the report. However, this is not always the case. Check your record set

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 2 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

The RecordSet object is the main interface to the information base that allows you to read, create and manipulate your data. It represents your data in a tabular format and is involved in almost all aspects of ADO. Therefore, you must check to see if your ADO/CDO/RDO RecordSet contains data. To do this, write out the contents of the ADO RecordSet in your ASP page. Use the following code for an ADO Object:

<%@ LANGUAGE="VBSCRIPT" %> <% Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open("LocalServer") set session("oRs") = oConn.Execute("Select * FROM authors") session("oRs").MoveFirst %>

> <%For Each oField In session("oRs").Fields %> <% Next %> <% Do While Not session("oRs").EOF %> <%For Each oField In session("oRs").Fields %> <% Next session("oRs").MoveNext %> <% Loop %>

Use the following code for a CDO (Crystal Data Object) Object:

<%@ Language=VBScript %>

<%

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 3 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

Set session("CDORowSet") = Server.CreateObject("CrystalDataObject.CrystalComObject")

session("CDORowSet").Addfield "Name" session("CDORowSet").Addfield "Phone"

dim rows(3,1)

rows(0,0) = cstr("Brent") rows(0,1) = cstr("(604) 555-1234")

rows(1,0) = cstr("Cal") rows(1,1) = cstr("(604) 555-2345")

rows(2,0) = cstr("Margaret") rows(2,1) = cstr("(604) 555-3456")

rows(3,0) = cstr("Dipesh") rows(3,1) = cstr("(604) 555-4567")

session("CDORowSet").AddRows rows

session("CDORowset").MoveFirst

i=1 %>

<% = oField.Name %>
<% If IsNull(oField) Then Response.Write " " Else Response.Write oField.Value End If %>
> <%For i=1 to session("CDORowset").GetColCount %> <% Next %>

<% Do While Not session("CDORowset").GetEOF %>

<%For i=0 to session("CDORowset").RowCount %> <% Next session("CDORowset").MoveNext %> <% Loop %>
<%=session("CDORowset").GetFieldName(cint(i-1))%>

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 4 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

<% If IsNull(session("CDORowset").GetFieldData(cint(i))) Then Response.Write " " Else Response.Write session("CDORowset").GetFieldData(cint(i)) End If %>

If the ADO RecordSet does not have any data in it, then the problem is either with your ADO code or with your ADO connection. Check to see if you have the file Msado15.dll and that you are making a connection to the program ID (ProgID) "ADODB."

If the ADO RecordSet does contain data, compare it to the structure defined by your .TTX file.

NOTE A TTX file or Data Definition file is a tab separated text file with a .TTX file extension.

Do they match EXACTLY? The recordset’s structure must be IDENTICAL to your .TTX file’s description. If not, the data will attempt to populate the report by “relative position”.

The layout of a .TTX file is as follows (note that each “field” is separated by tabs):

Column name Data type Size SampleData Check your report

Open the report in the Crystal Reports Designer. Under the File menu, ensure that Save Data With Report is selected. Make sure that the report is not saved with data. Calling the function call Session(“oRpt”).DiscardSavedData does not always seem to discard data saved with the report. If you are getting sample data (in the last column of the .ttx file) in the viewer you should definitely make sure that you are not saving data with the report.

In addition, make sure that:

• the UFL that is required for your report is also on the web server • all values are passed correctly to the parameter fields.

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 5 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

For information on how to call stored procedures containing parameters, refer to Microsoft’s Knowledge Base article Q185125 (HOWTO: Invoke a Stored Procedure w/ADO Query using VBA/C++/Java).

If your report contains subreports, then your ASP code must reflect that. For example:

'open the subreport - subreport name was taken from the subobj object. Set CRSubreports = session("oRpt").OpenSubreport("ADODemo.rpt")

'Create the ADO Database Connection:

Set oConn2 = Server.CreateObject("ADODB.Connection") oConn2.Open("ADO DEMO mdb") set session("oRs2") = oConn2.Execute("Select * FROM ADODemoTable") Set Database2 = CRSubreports.Database set Tables2 = Database2.Tables set Table1s = Tables2.Item(1) CRSubreports.DiscardSavedData

Table1s.SetPrivateData 3, session("oRs2")

Still having trouble?

If you are still having difficulty creating reports with ADO ASP, go back to the fundamentals to try to pinpoint exactly where the problem is. Make sure that your reports can be run through the URL line. Our sample reports at http://YourLocalHost/scrreports are a good way to test this, as we know they work and you can use them to check out both the Web Reports server and the Automation server. If any ASP connected with our reports does not work, you may want to check the ASP connection itself by running a simple test ASP file like the following:

<% Response.write “Hello, World.” %>

If the test ASP file does not run, then the problem may lie with your Internet Information Server (IIS) installation. Make sure that you have only one copy of the file Asp.dll and that it is version 1.17 or later. For a more recent version of this file, visit the Microsoft web site.

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 6 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

Once you have a more recent version of ASP.dll, you will have to unregister and reregister the Asp.dll and the Cpeaut32.dll making sure that the Asp.dll is registered first. You can then perform the following test ASP to check to see if you can create the application object:

<% If isObject (session(“oApp”)) Then Set session (“oApp”) = Server.CreateObject (“Crystal.CRPE.Application”) End If Response.write “Object Created” %> You can also obtain more helpful details about any errors your ADO ASP is generating by looping through the ADO errors collection using the following code: Dim errLoop , ErrCol ‘Cnn is the ADO connection object. Set ErrCol = Cnn.Errors ‘You can also check the other properties for Number, Source, SQLState and NativeError. For Each errLoop In ErrCol Response.write errLoop.Description & “
” Next1

We hope that the tips and suggestions provided in this paper have been helpful in clearing up difficulties encountered when using ADO with Crystal Reports. Finding More Information

The following reference materials were used to create this Tech Support document. They are recommended for further reading on ActiveX Data Objects.

Corning, Michael, Elfanbaum, Steve & Melnick David, Working with Active Server Pages. Que Corporation, Indianapolis, 1997.

Hettihewa, Sanjaya & Held, Kelly Active Server Pages. Sams.net Publishing, Indianapolis, 1997.

Hillier, Scot & Mezick, Daniel Programming Active Server Pages. Microsoft Press, Redmond, Washington, 1997.

http://www.microsoft.com/data/ado/adords15/

Crystal Reports Active Data Driver White Paper

1 “Troubleshooting ASP and ADO Errors,” Srinath Vasireddy, Microsoft Interactive Developer. November 1998, Volume 3 Number 11

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 7 Using Microsoft’s ActiveX Data Objects with the ASP Reports Server Troubleshooting ADO Issues

Steps to Diagnose Active Data Problems

Vasireddy, Srinath “Troubleshooting ASP and ADO Errors,” Microsoft Interactive Developer. November 1998, Volume 3 Number 11 Contacting Crystal Decisions for Technical Support

We recommend that you refer to the product documentation and that you visit our Technical Support web site for more resources.

Self-serve Support: http://support.crystaldecisions.com/

Email Support: http://support.crystaldecisions.com/support/answers.asp

Telephone Support: http://www.crystaldecisions.com/contact/support.asp

7/5/2002 2:19 PM Copyright  2001 Crystal Decisions, Inc. All Rights Reserved. Page 8