[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Crystal Reports 9 and ASP

Hello everybody,
I've been using VB6 and Crystal for awhile now, but now I have to convert my VB application to ASP.  All of my reports are already created in Crystal Reports 9.  I just have to display them in the browser.  Here's how it's going to work and the idea is pretty simple:

User goes to an ASP page.  Clicks on the link and previews a certain report in the browser via Crystal Reports where data is driven from Access XP database.

I told you the idea is pretty simple.

Now, how do I accomplish that?  I need a working example that does exactly that.  All of my reports have multiple subreports inside of them.

Thanks
0
pushkin
Asked:
pushkin
  • 3
  • 2
  • 2
2 Solutions
 
a1xCommented:
0
 
pushkinAuthor Commented:
Thanks for your resource, but it's only for ASP.net.  I'm doing this in ASP, plus I'm new to ASP so it would be hard for me to follow in .Net.

Thanks
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
pushkinAuthor Commented:
Again, thanks for the link.  I tried it, but the ReadMe.txt says that I need Movie.dbf file, which is not included in the zip.  There is no documentation or explanation on how to get it up and running successfully.  I would like to see a working example, so I can apply the same logic to my own reports.  Thanks for the time.
0
 
kssaranCommented:
Try this

set session("oRs") = Recordset

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

' 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: http://Domain/Dir)

'OPEN THE REPORT (but destroy any previous one first)

If IsObject(session("oRpt")) then
Set session("oRpt") = nothing
End if

Set session("oRpt") = session("oApp").OpenReport(path & reportname, 1)

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

'Now we must tell the report to report off of the data in the ADO recordset:

'To base a report on data from a dynamically generated ADO recordset, we must
'build the report based on the data structure of the recordset we will create.
'Then at runtime, we tell the report to report off of the data in the ADO Record set.
'The report is currently created against a database structure file (ADORecordset.ttx)
'This ttx file contains the structure of the recordset, and not the actual data.

'A Crystal Report is completely dependant on the structure of the dataset the report
'will use. Therefor it is important that your database structure (ttx file) or DSN
'reflects EXACTLY the data that is contained in the ADO recordset at runtime.

session("oRpt").DiscardSavedData

set Database = session("oRpt").Database
'Instantiates a database collection which references the database(s) used in the report.

set Tables = Database.Tables
'Instantiates a Tables collection which references the Tables of the Database object.

set Table1 = Tables.Item(1)
'Instantiates a table object which references the first table used in the report.
'In this case this table object currently refers to the ADORecordset.ttx file.

Table1.SetPrivateData 3, session("oRs")

'The "SetPrivateData" line tells the report that it datasource is now the recordset
'Now the report will display the data contained in the session("oRs") record set.
'If your report contained a subreport that was based off this or a different reordset
'you must follow the same steps above only referencing the subreport object.
'
'
'====================================================================================
' Retrieve the Records and Create the "Page on Demand" Engine Object
'====================================================================================

'On Error Resume Next
session("oRpt").ReadRecords

If Err.Number <> 0 Then
Response.Write "An Error has occured on the server in attempting to access the data source"
Else

If IsObject(session("oPageEngine")) Then
set session("oPageEngine") = nothing
End If
set session("oPageEngine") = session("oRpt").PageEngine
End If

' 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, SmartViewerJave.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.

'Pass in dynamic values (titles etc)
'Title
'session("oRpt").formulafields.item(1).text = "'All Years for Contract " & cover & " Report for " & usertext & "'"

'dim sURL
'sURL = "SmartViewerActiveX.asp?refback=" & Server.urlencode(Request.querystring("refback").item)


%>
<!--#include file="SmartViewerActiveX.htm" -->



SmartViewerActiveX.htm contains


<OBJECT id="CRViewer"
codeBase="/viewer/activeXViewer/activexviewer.cab#Version=8,0,0,224"
classid=CLSID:C4847596-972C-11D0-9567-00A0C9273C2A width="100%" height="95%"><PARAM NAME="DisplayGroupTree" VALUE="0"><PARAM NAME="DisplayToolbar" VALUE="-1"><PARAM NAME="EnableGroupTree" VALUE="-1"><PARAM NAME="EnableNavigationControls" VALUE="-1"><PARAM NAME="EnableStopButton" VALUE="-1"><PARAM NAME="EnablePrintButton" VALUE="-1"><PARAM NAME="EnableZoomControl" VALUE="-1"><PARAM NAME="EnableCloseButton" VALUE="-1"><PARAM NAME="EnableProgressControl" VALUE="-1"><PARAM NAME="EnableSearchControl" VALUE="-1"><PARAM NAME="EnableRefreshButton" VALUE="-1"><PARAM NAME="EnableDrillDown" VALUE="-1"><PARAM NAME="EnableAnimationControl" VALUE="-1"><PARAM NAME="EnableSelectExpertButton" VALUE="0"><PARAM NAME="EnableToolbar" VALUE="-1"><PARAM NAME="DisplayBorder" VALUE="-1"><PARAM NAME="DisplayTabs" VALUE="-1"><PARAM NAME="DisplayBackgroundEdge" VALUE="-1"><PARAM NAME="SelectionFormula" VALUE=""><PARAM NAME="EnablePopupMenu" VALUE="-1"><PARAM NAME="EnableExportButton" VALUE="0"><PARAM NAME="EnableSearchExpertButton" VALUE="0"><PARAM NAME="EnableHelpButton" VALUE="0"></OBJECT>

<script LANGUAGE="VBScript">
<!--
Sub Page_Initialize
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBroker.WebReportBroker")
if ScriptEngineMajorVersion < 2 then
window.alert "IE 3.02 users on NT4 need to get the latest version of VBScript or install IE 4.01 SP1. IE 3.02 users on Win95 need DCOM95 and latest version of VBScript, or install IE 4.01 SP1. These files are available at Microsoft's web site."
CRViewer.ReportName = Location.Protocol + "//" + Location.Host + "/scrsamples/Web Component Server/rptserver.asp"
else
Dim webSource
Set webSource = CreateObject("WebReportSource.WebReportSource")
webSource.ReportSource = webBroker
webSource.URL = "rptserver.asp" 'Location.Protocol + "//" + location.Host + "/scrsamples/Web Component Server/rptserver.asp"
webSource.PromptOnRefresh = True
CRViewer.ReportSource = webSource
end if
CRViewer.EnableExportButton = true
CRViewer.EnableRefreshButton = false
CRViewer.ViewReport
<%if Session("ReportDetail") = "Total" then
Response.write("CRViewer.Zoom(90)" & chr(13))
Response.write("CRViewer.DisplayGroupTree = false")
else
Response.write("CRViewer.Zoom(75)" & chr(13))
Response.write("CRViewer.DisplayGroupTree = True")
end if%>
End Sub
-->
</script>


Rgds
Sara
0
 
pushkinAuthor Commented:
Thanks for your post kssaran.  I placed your code in my asp page, but I'm getting just a gray screen with a red X in the top left corner and nothing is displaying.  What else should I change?  And what about the first line in your code,
set session("oRs") = Recordset

Do I actually assign an ADO recordset there?

Please explain.

Thanks for your time
0
 
kssaranCommented:
If you have proper Crystal Report software with you. I would request you to install Web Component Server (WCS) included with Crystal Reports. You will get all the proper working code in that as different type of web services. You can find it in the setup of crystal Report.

Thanks & Rgds
Sara
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now