First I create the report from a stored proc in SQL and save it w/out the data.
Here is a snipit of code I use to run it from .NET:
' To be able to get the values in web.config
Dim MachineType As String = System.Environment.GetEnvironmentVariable("MachineType"
' Load the selected report
Dim crReportDocument As New ReportDocument()
Dim sbPath As New System.Text.StringBuilder()
sbPath.Append(System.Configuration.ConfigurationSettings.GetConfig(MachineType)("DatabasePhysicalPath")
sbPath.Append(System.Configuration.ConfigurationSettings.GetConfig(MachineType)("CrystalFilesLocation")
sbPath.Append(_strFileName)
'Load the Report
Dim ErrorHandling As New ErrorHandlingUtils()
Try
crReportDocument.Load(sbPath.ToString)
Catch exc As System.Exception
Dim sourcepage As PageBase = CType(context.Handler, PageBase)
ErrorHandling.SendToErrorPage(Me, exc, REDIRECT_PAGE, sourcepage)
Finally
ErrorHandling = Nothing
End Try
' Get the logon information from web.config
Dim crConnectionInfo As New ConnectionInfo()
crConnectionInfo.ServerName = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportServerName"
crConnectionInfo.DatabaseName = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportDatabaseName"
crConnectionInfo.UserID = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportUserID"
crConnectionInfo.Password = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportPassword"
' Get the tables collection from the report object to apply logon information
Dim crDatabase As Database = crReportDocument.Database
Dim crTables As Tables = crDatabase.Tables
' Apply the logon information to each table in the collection
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTableLogonInfo As TableLogOnInfo
For Each crTable In crTables
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.ConnectionInfo = crConnectionInfo
crTableLogonInfo.TableName = crTable.Name
crTable.ApplyLogOnInfo(crTableLogonInfo)
crTable.Location = crTable.Name
Next
' Get the collection of parameters from previous page
Dim arParms As SqlClient.SqlParameter()
If Not Page.IsPostBack Then
arParms = sourcepage.CrystalParams
Session("ParamsCollection" = arParms
Else
arParms = Session("ParamsCollection"
End If
' Apply the parameters to the report document
RetrieveInitialRptParams(arParms, crReportDocument.DataDefinition.ParameterFields)
' Make the report the source for the viewer
crvReport.ReportSource = crReportDocument
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.