pushkin
asked on
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
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
http://www.businessobjects.com/products/dev_zone/net_walkthroughs.asp has sample code on how it can be done.
ASKER
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
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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("Cryst alRuntime. Applicatio n")
End If
' CREATE THE REPORT OBJECT
'
'The Report object is created by calling the Application object's OpenReport method.
Path = Request.ServerVariables("P ATH_TRANSL ATED")
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").MorePrintE ngineError Messages = False
session("oRpt").EnablePara meterPromp ting = 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").DiscardSav edData
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").ReadRecord s
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("oPageEng ine")) 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").formulafi elds.item( 1).text = "'All Years for Contract " & cover & " Report for " & usertext & "'"
'dim sURL
'sURL = "SmartViewerActiveX.asp?re fback=" & Server.urlencode(Request.q uerystring ("refback" ).item)
%>
<!--#include file="SmartViewerActiveX.h tm" -->
SmartViewerActiveX.htm contains
<OBJECT id="CRViewer"
codeBase="/viewer/activeXV iewer/acti vexviewer. cab#Versio n=8,0,0,22 4"
classid=CLSID:C4847596-972 C-11D0-956 7-00A0C927 3C2A width="100%" height="95%"><PARAM NAME="DisplayGroupTree" VALUE="0"><PARAM NAME="DisplayToolbar" VALUE="-1"><PARAM NAME="EnableGroupTree" VALUE="-1"><PARAM NAME="EnableNavigationCont rols" VALUE="-1"><PARAM NAME="EnableStopButton" VALUE="-1"><PARAM NAME="EnablePrintButton" VALUE="-1"><PARAM NAME="EnableZoomControl" VALUE="-1"><PARAM NAME="EnableCloseButton" VALUE="-1"><PARAM NAME="EnableProgressContro l" VALUE="-1"><PARAM NAME="EnableSearchControl" VALUE="-1"><PARAM NAME="EnableRefreshButton" VALUE="-1"><PARAM NAME="EnableDrillDown" VALUE="-1"><PARAM NAME="EnableAnimationContr ol" VALUE="-1"><PARAM NAME="EnableSelectExpertBu tton" VALUE="0"><PARAM NAME="EnableToolbar" VALUE="-1"><PARAM NAME="DisplayBorder" VALUE="-1"><PARAM NAME="DisplayTabs" VALUE="-1"><PARAM NAME="DisplayBackgroundEdg e" VALUE="-1"><PARAM NAME="SelectionFormula" VALUE=""><PARAM NAME="EnablePopupMenu" VALUE="-1"><PARAM NAME="EnableExportButton" VALUE="0"><PARAM NAME="EnableSearchExpertBu tton" VALUE="0"><PARAM NAME="EnableHelpButton" VALUE="0"></OBJECT>
<script LANGUAGE="VBScript">
<!--
Sub Page_Initialize
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBro ker.WebRep ortBroker" )
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("WebReportSou rce.WebRep ortSource" )
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.EnableExportButto n = true
CRViewer.EnableRefreshButt on = false
CRViewer.ViewReport
<%if Session("ReportDetail") = "Total" then
Response.write("CRViewer.Z oom(90)" & chr(13))
Response.write("CRViewer.D isplayGrou pTree = false")
else
Response.write("CRViewer.Z oom(75)" & chr(13))
Response.write("CRViewer.D isplayGrou pTree = True")
end if%>
End Sub
-->
</script>
Rgds
Sara
set session("oRs") = Recordset
'=========================
'Create the Crystal Reports Objects
'=========================
' CREATE THE APPLICATION OBJECT
If Not IsObject (session("oApp")) Then
Set session("oApp") = Server.CreateObject("Cryst
End If
' CREATE THE REPORT OBJECT
'
'The Report object is created by calling the Application object's OpenReport method.
Path = Request.ServerVariables("P
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
session("oRpt").MorePrintE
session("oRpt").EnablePara
'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").DiscardSav
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").ReadRecord
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("oPageEng
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,
'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").formulafi
'dim sURL
'sURL = "SmartViewerActiveX.asp?re
%>
<!--#include file="SmartViewerActiveX.h
SmartViewerActiveX.htm contains
<OBJECT id="CRViewer"
codeBase="/viewer/activeXV
classid=CLSID:C4847596-972
<script LANGUAGE="VBScript">
<!--
Sub Page_Initialize
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBro
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("WebReportSou
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.EnableExportButto
CRViewer.EnableRefreshButt
CRViewer.ViewReport
<%if Session("ReportDetail") = "Total" then
Response.write("CRViewer.Z
Response.write("CRViewer.D
else
Response.write("CRViewer.Z
Response.write("CRViewer.D
end if%>
End Sub
-->
</script>
Rgds
Sara
ASKER
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
set session("oRs") = Recordset
Do I actually assign an ADO recordset there?
Please explain.
Thanks for your time
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.