Saturday, February 25, 2012

Crystal 10 Using ASP page for datebase connections

I hope someone can help me get started on this. I wish I knew all of the terminology to use for this, but I have limited knowledge of Crystal Enterise 10. I am trying to figure this out as the person who created it is no longer around. He is my problem. I have a Crystal report ( Crystal 10) that has two subreports. The main report and the two subreports are all from different datasources. The report runs fine on my machine using the Crystal application. The problem comes in when I run it via Internet Explorer. There is an ASP page that is used to pass the connection information to the Crystal report. It works fine via the web with only one subreport. I can not figure out how to add the third datasource to the ASP page. I will include the ASP page that is used for the two current connections. What I need to know is how to add the third datasource connection to the existing information. I am going to attach a PDF of the code. Thank you for your help.

<%@. Language=VBScript CodePage=65001 %>
<%

'=======================================================================
' CRYSTAL ENTERPRISE REPORT APPLICATION SERVER (CE EMBEDDED) 10
' Purpose: Demonstrate how to change the datasource location at runtime
' Special Note* - ODBC Datasources
'=======================================================================

' This line creates a string variable called reportName that we will use to pass
' the Crystal Report file name (.rpt file) to the OpenReport method.

reportname = "Reports/"&Request("CRReport")

'============================================================================
' CREATE THE REPORT CLIENT DOCUMENT OBJECT AND OPEN THE REPORT
'============================================================================

' Use the Object Factory object to create other RAS objects (useful for versioning changes)
Set objFactory = CreateObject("CrystalReports.ObjectFactory")

' This "While/Wend" loop is used to determine the physical path (eg: C:\) to the
' Crystal Report .rpt by translating the URL virtual path (eg: http://Domain/Dir)
Dim path, iLen

path = Request.ServerVariables("PATH_TRANSLATED")

While (Right(path, 1) <> "\" And Len(path) <> 0)
iLen = Len(path) - 1
path = Left(path, iLen)
Wend

' Create a new ReportClientDocument object
Set Session("oClientDoc") = objFactory.CreateObject("CrystalClientDoc.ReportClientDocument")

' Specify the RAS Server (computer name or IP address) to use (If SDK and RAS Service are running on seperate machines)
Session("oClientDoc").ReportAppServer = "localhost"

' Open the report object to initialize the ReportClientDocument
Session("oClientDoc").Open path & reportName

'===============================================================
' CHANGING THE MAIN REPORT DATABASE INFO
'===============================================================
Set oDBInfo = Session("oClientDoc").DatabaseController.GetConnectionInfos().Item(0)
oDBInfo.UserName = "sa"
oDBInfo.Password = "blackfin"

'Get the collection of tables in the main report
Set Tables = Session("oClientDoc").DataDefController.Database.Tables
For Each table in Tables

'clone the table object
Set newTable = Table.Clone

'set the table's connectionInfo to the current connection info
newTable.ConnectionInfo = oDBInfo

'set the table object qualified name to include the new database name
'i.e. original = 'db1.dbo.myTable', new = 'db2.dbo.myTable'
'newTable.QualifiedName = Database & ".dbo." & Table.Name

'put this newly modified table object back into the report client doc
Session("oClientDoc").DatabaseController.SetTableLocation table, newTable

Next

'===============================================================
' CHANGING THE DATABASE FOR ALL SUBREPORTS
'===============================================================

'get a collection of subreport names
Set subReportNames = Session("oClientDoc").SubReportController.QuerySubreportNames

For each subName in subReportnames

'we can't reference a subreport table object directly, so we get the collection of tables first
Set subTables = Session("oClientDoc").SubReportController.GetSubreportDatabase(subName).Tables

For each subTable in subTables

'clone the subreport table object
Set newSubTable = subTable.Clone

'set the subreport table's connectionInfo to the current connection info
newSubTable.ConnectionInfo.UserName = "william_l"
newSubTable.ConnectionInfo.Password = "bdl700"

'set the table object qualified name to include the new database name
'i.e. original = 'db1.dbo.myTable', new = 'db2.dbo.myTable'
'newSubTable.QualifiedName = Database & ".dbo." & subTable.Name

'put this newly modified table object back into the report client doc
Session("oClientDoc").SubReportController.SetTableLocation subName, subTable, newSubTable
'on error resume next
Next
Next

'============================================================================
' CHOOSING THE REPORT VIEWER
'============================================================================
'
' There are four Report Viewers:
' 1. Crystal Reports Interactive Viewer (CrystalReportsInteractiveViewer.asp)
' 2. Crystal Reports Viewer (CrystalReportsViewer.asp)
' 3. Crystal Reports Parts Viewer (CrystalReportsPartsViewer.asp)
' 4. Legacy ActiveX Viewer (ActiveXViewer.asp)
'
' Note that to use this these viewers you must have the appropriate .asp file in the
' same virtual directory as the main ASP page. Choose from one of the four viewers below,
' simply uncomment the one you want to use:

' *** Crystal Reports Interactive Viewer ***
Response.Redirect "CrystalReportsInteractiveViewer.asp"

' *** Crystal Reports Viewer ***
'Response.Redirect "CrystalReportsViewer.asp"

' IMPORTANT NOTE - To use the report parts viewer successfully you are required to
' choose and name three objects in the report to Node1, Node2 and Node3.
' You can access an objects name by using the Format Editor dialog box.
' For more information on the Format Editor Dialog Box and setting objects
' names, please refer to the Help Contents (Help Menu->Crystal Reports Help)
' or by pressing F1

' *** Crystal Reports Parts Viewer ***
'Response.Redirect "CrystalReportsPartsViewer.asp"

' IMPORTANT NOTE - The ActiveXviewer does NOT have the ability to prompt for parameters,
' selection formulas, or login information. If your report requires this information
' to run, look at the the appropriate code samples to pass this information before
' using this viewer.

' *** Legacy ActiveX Viewer ***
'Response.Redirect "ActiveXViewer.asp"

'=============================================================================

%>
%>Hi, Does anyone have an ideas? Does my question make sense?
Thank you|||What I see is that the line that change to new database location is a comment

'newSubTable.QualifiedName = Database & ".dbo." & subTable.Name|||Thank you jggtz for the reply.
Would the Database piece be the ODBC name? What needs to be modified on the ".dbo." section? Does the subTable.Name stay like it is?

You don't know how much I appreciate your help.

Thank you.|||Maybe this can help -->
http://www.codeproject.com/aspnet/crystalwithaspdotnet.asp?df=100&forumid=188132&exp=0&select=1455404

No comments:

Post a Comment