chiplarsen
IS-IT--Management
We currently view Crystal Reports via CE 10 using Internet Explorer. We have these ASP pages that contain the login information for the ODBC connections used in the reports. That information is passed in IE so the user does not have to enter login information. We had to modify the ASP page so it reflects the DB information. There is a section for your main report and also a section for a subreport. I will include the code for it below. The problem is now I have two subreports in one report. I do not know how to add a third ODBC connection to the ASP page. Has anyone done that before? We are using CE 10.0. Thank you
Code:
<%@ 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: [URL unfurl="true"]http://Domain/Dir)[/URL]
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