Umm...that depends on what kind of connectivity you are using. Are you using an ODBC connection? OLEDB? ADO recordset? And, just as a point of reference, how are you setting up the connection for the main report?
<%
response.expires = 0
Server.ScriptTimeout = 3600
IF request.querystring("go" <> "" Then
session("report" = request.querystring("go"
End If
'Open Connection to Database
reportname = "reports\" & session("report" & ".rpt"
' CREATE THE APPLICATION OBJECT
If Not IsObject (session("oApp") Then
Set session("oApp" = Server.CreateObject("Crystalruntime.Application"
End If
Path = Request.ServerVariables("PATH_TRANSLATED"
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
'response.write "first thru " & path & " "
path = left(path, (len(path) - 1))
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
'OPEN THE REPORT (but destroy any previous one first)
If IsObject(session("oRpt") then
Set session("oRpt" = nothing
End if
'Response.Write path & reportname
On error resume next
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.
If Err.Number <> 0 Then
response.write "report path " & path & reportname & " "
Response.Write "Error Occurred creating Report Object: " & Err.Description & err.number
Set Session("oRpt" = nothing
Set Session("oApp" = nothing
Session.Abandon
Response.End
End If
'This On error resume next block checks for any errors on creating the report object
'we are specifically trapping for an error if we try to surpass the maximum concurrent
'users defined by the license agreement. By destroying the application and report objects
'on failure we ensure that this client session will be able to run reports when a license is free
'
'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.
'These lines disable the Error reporting mechanism included the built into the
'Crystal Report Design Component automation server (craxdrt.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).
session("oRpt".DiscardSavedData
set crtable = session("oRpt".Database.Tables.Item(1)
crtable.SetLogonInfo "dsn", "server name", "password", "userid"
'response.write crtable.testconnectivity
‘select case is for multiple reports… and the parameter fields if you don’t have any don’t worry about the ‘select section
select case session("report"
case "xxx","xxx1"
case "xxx3"
Session("oRpt".ParameterFields.GetItemByName("@status".AddCurrentValue(cstr(request.querystring("status1"))
end select
'====================================================================================
' 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 session("report" & " Date " & cdate(vdate) & " "
response.write "connectivity " & crtable.testconnectivity & " "
response.write crtable.SetLogonInfo
Response.Write "Error Occurred Reading Records: " & Err.Description & err.number
Set Session("oRpt" = nothing
Set Session("oApp" = nothing
Session.Abandon
Response.End
Else
If IsObject(session("oPageEngine") Then
set session("oPageEngine" = nothing
End If
set session("oPageEngine" = session("oRpt".PageEngine
End If
'There are other viewer that can be used but the activex allows us let the user print the report out.
%>
<!-- #include file="../common/crystal/SmartViewerActiveX.asp" -->
<title>this is a example of the crystal setup.</title>
Here is some sample code. It assumes a subreport called "Titles".
Set subReportOne = session("oRpt".OpenSubReport("Titles"
Set subReportOneTablesCollection = subReportOne.Database.Tables
For Each crTable in SubReportOneTablesCollection
crtable.SetLogonInfo "dsn", "server name", "password", "userid"
Next
Place this code before the section starting with comment block:
'====================================================================================
' Retrieve the Records and Create the "Page on Demand" Engine Object
'====================================================================================
If you need a more generic approach (in the event you don't want to hardcode the subreport name), you can iterate through the report objects, looking for objects of the kind crSubreportObject.
The following is some vb code that shows how to do that. You should be able to adapt it for your asp application if necessary:
Dim subReport As SubreportObject
Dim sect As Section
Dim rptObject As Object
For Each sect In Report.Sections
For Each rptObject In sect.ReportObjects
If rptObject.Kind = crSubreportObject Then
Set subReport = rptObject
'Do your login code here
The weird thing with this problem it works in Crystal but not on the ASP page and if I take out the checks for the parameters being passed it works - why does it do that.
Well, as for why you don't get the same behavior when designing the report, the Crystal Designer automatically passes the logon info to the subreport if the logon info is the same as the main report. The RDC, which your asp pages are using, doesn't do that (it doesn't do it in vb, either).
As for the 2nd part, about the parameters, without seeing how you are using the parameters and what, if any, relationship they have to the subreport, I really can't answer. However, I really don't see how the subreports could work at all without using SetLogOnInfo, unless your database doesn't require authentication (or, if SQL Server, is using NT Authentication).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.