Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal 10 Viewer Displays but is empty (Migration from crystal 8)

Status
Not open for further replies.

ckwizard77

Programmer
Jan 8, 2003
29
US
I have tried to migrate my crystal reports 8 to crystal reports 10. I tried bringing the reports in to Crystal 10 saving, reconnecting to db and running them without changing the code, but I cannot get a report to display. The reports will display when I run them through Crystal, but ont in my ASP code. I get the viewer, but no report. I am probably missing something in my code and I am not sure what. Any help would be appreciated. I have attached the code for your review.

************************************************************
The Parameters and Values are passed here:
************************************************************
str1="/Reports10/genReport.asp?reportname=Summary.rpt" & _
"&prompt0=" & s_Boro & "&prompt1=" & s_Category & "&prompt2=" & _ s_Year &
"&prompt3=" & i_Boro & "&prompt4=" & i_Category & "&promptOnRefresh=0"

************************************************************
This is the page that receives parses the data, adds CurrentValues and call the ActiveXViewer:
************************************************************
%@ Language=VBScript %>
<!-- #INCLUDE FILE="../common/session_check.asp"-->
<!-- #INCLUDE FILE="../common/ClsCrystalLogon.asp"-->

<%dim crReport
dim s_reportname
dim s_param
dim i_counter
dim s_paramname
s_paramname="param"
if request(s_paramname & "0")="" then
s_paramname="prompt"
end if
i_counter=0
s_reportname=request("reportname")
if s_reportname>"" then
set crReport=new ClsCrystalLogon
with crReport
.ReportName=s_reportname
.ServerKey="Etrac_Servername"
.DBKey="Etrac_InitialCatalog"
.UserKey="Etrac_Userid"
.PwdKey="Etrac_Pwd"
s_param=request(s_paramname & "0")
while s_param>""
.addParam replace(s_param, "*","%")
i_counter=i_counter+1
s_param=request(s_paramname & i_counter)
wend
end with
'Generate report
crReport.genReport
end if
%>

***********************************************************
This is the INCLUDE FILE="../common/ClsCrystalLogon.asp
***********************************************************
<%
Class ClsCrystalLogon
private s_reportname
private a_ParamColl, i_ParamCount
private s_serverkeyname
private s_dbkeyname
private s_userkeyname
private s_pwdkeyname

private sub class_initialize()
i_ParamCount = 0
ReDim a_ParamColl(0)
end sub

public Sub addParam(byval v_Param)
ReDim Preserve a_ParamColl(i_ParamCount)
a_ParamColl(i_ParamCount) = v_Param
i_ParamCount = i_ParamCount+1
end Sub

public Property Get ReportName()
ReportName=s_reportname
End Property
public Property Let ReportName(rptName)
s_reportname=rptName
End Property

public Property Get ServerKey()
ServerKey=s_serverkeyname
End Property
public Property Let ServerKey(s_svrkey)
s_serverkeyname=s_svrkey
End Property

public Property Get DBKey()
DBKey=s_dbkeyname
End Property
public Property Let DBKey(s_dbkey)
s_dbkeyname=s_dbkey
End Property

public Property Get UserKey()
UserKey=s_userkeyname
End Property
public Property Let UserKey(s_usrkey)
s_userkeyname=s_usrkey
End Property

public Property Get PwdKey()
PwdKey=s_pwdkeyname
End Property

public Property Let PwdKey(s_pwdkey)
s_pwdkeyname=s_pwdkey
End Property

private sub crCheckForError()
if err.number<>0 then
Response.Write("<br><i>An error occurred while generating report: </i><br>")
Response.Write("<br>Error Number -> " & cstr(Err.Number))
Response.write("<BR>Error Source -> " & Err.Source)
Response.Write("<BR>Error Description -> " & Err.Description)
Response.end
Err.Clear
end if
end sub

public function genReport()
Dim objConnectionInfo
dim s_server
dim s_db
dim s_user
dim s_pwd
dim i_counter
On Error Resume Next
' = = = = = = = = = = = = = = = = = = = = = = = = = =
' Working with the Setlogoninfo method
' = = = = = = = = = = = = = = = = = = = = = = = = = =
'
'
' CONCEPT:
'
' This appliction demonstrates the user of Setlogoninfo. There are two ways
' to log on to a datasource using the Automation Server. One is to use the
' LogonServer method, which applies to the Application object, and the other
' is to use SetLogonInfo, which works with the Database Table object.
' Two advantages of using SetLogonInfo are that you can set different datasources
' for subreports, and you can use the 'MatchLogonInfo' property. If you don't use this
' property and an authenticated user is previewing reports, anybody else using the
' same id without a password can also execute the same asp page and preview the reports.

'==========================================================
'Create the Crystal Reports Objects
'==========================================================
'
'You will notice that the Crystal Reports objects are scoped as session variables.
'This is because the page on demand processing is performed by a prewritten
'ASP page called "rptserver.asp". In order to allow rptserver.asp easy access
'to the Crystal Report objects, we scope them as session variables. That way
'any ASP page running in this session, including rptserver.asp, can use them.

reportname = s_reportname

'This line creates a string variable called reportname that we will use to pass
'the Crystal Report filename (.rpt file) to the OpenReport method.
'To re-use this code for your application you would change the name of the report
'so as to reference your report file.

' CREATE THE APPLICATION OBJECT
If Not IsObject (session("oApp")) Then
Set session("oApp") = Server.CreateObject("CrystalRuntime.Application")
End If

'This "if/end if" structure is used to create the Crystal Reports Application
'object only once per session. Creating the application object - session("oApp")
'loads the Crystal Reports automation server (cpeaut32.dll) into memory.
'
'We create it as a session variable in order to use it for the duration of the
'ASP session. This is to elimainate the overhead of loading and unloading the
'cpeaut32.dll in and out of memory. Once the application object is created in
'memory for this session, you can run many reports without having to recreate it.

' CREATE THE REPORT OBJECT
'
'The Report object is created by calling the Application object's OpenReport method.

Path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend

'This "While/Wend" loop is used to determine the physical path (eg: C:\) to the
'Crystal Report file by translating the URL virtual path (eg:
'OPEN THE REPORT
'Response.Write path & reportname
'Response.end
Set session("oRpt") = session("oApp").OpenReport(path & reportname, 1)


'This line uses the "PATH" and "reportname" variables to reference the Crystal
'Report file, and open it up for processing.
'
'Notice that we do not create the report object only once. This is because
'within an ASP session, you may want to process more than one report. The
'rptserver.asp component will only process a report object named session("oRpt").
'Therefor, if you wish to process more than one report in an ASP session, you
'must open that report by creating a new session("oRpt") object.

session("oRpt").MorePrintEngineErrorMessages = False
session("oRpt").EnableParameterPrompting = False

'These lines disable the Error reporting mechanism included the built into the
'Crystal Report Print Engine (CRPE32.DLL). This is done for two reasons:
'
'1. The print engine is executed on the Web Server, so any error messages
' will be displayed there. If an error is reported on the web server, the
' print engine will stop processing and you application will "hang".
'
'2. This ASP page and rptserver.asp have some error handling logic desinged
' to trap any non-fatal errors (such as failed database connectivity) and
' display them to the client browser.
'
'**IMPORTANT** Even though we disable the extended error messaging of the engine
'fatal errors can cause an error dialog to be displayed on the Web Server machine.
'For this reason we reccomend that you set the "Allow Service to Interact with Desktop"
'option on the "World Wide Web Publishing" service (IIS service). That way if your ASP
'application freezes you will be able to view the error dialog (if one is displayed).


' ========================================================================
' Working with Setlogoninfo
' ========================================================================
'
' The datasource here is called Automation. It is a System Datasource, and points to the
' pubs database, which is installed with SQL Server. The Setlogoninfo method requires 4 parameters. The
' First parameter is the Server name and the second object is the database name. The third
' object is the Username followed by the password.

' We first set the oApp object to verify and authenticate the logons.

'set Session("options") = Session("oApp").options
'Session("options").MatchLogonInfo = 1

' We then set the location of each of the tables. In this example we have 3 tables therefore you
' will notice that the same code is repeated 3 times and the table number is changed accordingly.
' If you only have 1 table in your report you only need the first 2 lines below.
Set objConnectionInfo = New ClsGetConnectionInfo
With objConnectionInfo
s_server=.GetApplicationVariables(s_serverkeyname)
s_db=.GetApplicationVariables(s_dbkeyname)
s_user=.GetApplicationVariables(s_userkeyname)
s_pwd=.GetApplicationVariables(s_pwdkeyname)
end with

for each tbl in session("oRpt").Database.Tables
tbl.SetLogOnInfo cstr(s_server) ,cstr(s_db), cstr(s_user), cstr(s_pwd)
next

for each sec in session("oRpt").sections
for each tReportObject in sec.ReportObjects
if tReportObject.kind = 5 then'Constant equiv for crSubreportObject
Set tSubrepObject = sec.ReportObjects.item(tReportObject.name)
Set tSubreport = tSubrepObject.OpenSubreport
Set tDatabase = tSubreport.Database
Set tDatabaseTables = tDatabase.Tables
for each tDatabaseTable in tDatabaseTables
tDatabaseTable.SetLogOnInfo cstr(s_server) ,cstr(s_db), cstr(s_user), cstr(s_pwd)
next
end if
next
next

' Here we create a new report object which references the subreport.

'set Session("osubrpt")=session("orpt").opensubreport("subreportnameasstring")

' Now we will call Setlogoninfo for the table in the subreport.

'=================================================================
' Retrieve the Records and Create the "Page on Demand" Engine Object
'================================================================
'Param Field Type VBScript Call Type Number
'
'NumberField CDbl 7
'CurrencyField CDbl 8
'Boolean CBool 9
'StringField CStr 12
i_counter=0

for each prm in session("oRpt").ParameterFields
select case prm.ValueType
case 12
call prm.SetCurrentValue(cstr(a_ParamColl(i_counter)),prm.ValueType)
case 7,8
call prm.SetCurrentValue(cdbl(a_ParamColl(i_counter)),prm.ValueType)
case else
call prm.SetCurrentValue(a_ParamColl(i_counter),prm.ValueType)
end select
i_counter=i_counter+1
next

session("oRpt").ReadRecords
crCheckForError
If IsObject(session("oPageEngine")) Then
set session("oPageEngine") = nothing
End If
set session("oPageEngine") = session("oRpt").PageEngine
' INSTANTIATE THE CRYSTAL REPORTS SMART VIEWER
'
'When using the Crystal Reports automation server in an ASP environment, we use
'the same page on demand "Smart Viewers" used with the Crystal Web Report Server.
'The are four Crystal Reports Smart Viewers:
'
'1. ActiveX Smart Viewer
'2. Java Smart Viewer
'3. HTML Frame Smart Viewer
'4. HTML Page Smart Viewer
'
'The Smart Viewer that you use will based on the browser's display capablities.
'For Example, you would not want to instantiate the Java viewer if the browser
'did not support Java applets. For purposes on this demo, we have chosen to
'define a viewer. You can through code determine the support capabilities of
'the requesting browser. However that functionality is inherent in the Crystal
'Reports automation server and is beyond the scope of this demonstration app.
'
'We have chosen to leverage the server side include functionality of ASP
'for simplicity sake. So you can use the SmartViewer*.asp files to instantiate
'the smart viewer that you wish to send to the browser. Simply replace the line
'below with the Smart Viewer asp file you wish to use.
'
'The choices are SmartViewerActiveX.asp, SmartViewerJava.asp,
'SmartViewerHTMLFrame.asp, and SmartViewerHTMLPAge.asp.
'Note that to use this include you must have the appropriate .asp file in the
'same virtual directory as the main ASP page.
'
'*NOTE* For SmartViewerHTMLFrame and SmartViewerHTMLPage, you must also have
'the files framepage.asp and toolbar.asp in your virtual directory.
'<!-- #include file="../REPORTS/SmartViewerActiveX.asp" -->
'<!-- #include file="../REPORTS/SmartViewerHTMLPage.asp" -->

'If Err.Number <> 0 Then
' Response.Write err.Description
' Response.end
'end if
on error goto 0
%>

<!-- #include file="../reports/SmartViewerActiveX.asp" -->

<%
end function
end class%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top