I have been trying unsuccessfully to get Crystal reports to display a web page report for some time. It works on our prod environment, but not on a dev server or on a developer PC. I have tried installing Crystal Reports version 11, 11.5, and 11.5R2, but to no avail.
Everytime I run the project it gives the same error on the viewer when the web page displays: "Object reference not set to an instance of an object".
My current configuration is Crystal Reports 11.5R2. It is using crystalreportviewers115 in IIS.
Most of the google results for this error indicated a problem with crystalreportsviewers, but I don't see anything that is incorrect.
Can anyone shed some light on this issue, or tell me how to troubleshoot it?
Thanks,
Robert Thompson
Here is the code in the project which runs with no errors:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim SvrName As String
Dim DbName As String
Dim rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim oLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim oTable As CrystalDecisions.CrystalReports.Engine.Table
Dim reportDocument1 As New ReportDocument
Dim ContainsKey As Boolean
Dim tmpStr As String
' The file name of the report to generate, should not
' be the full path, just the file name and extension.
Try
Select Case Request.QueryString.Count
Case 1
If Not Request.QueryString("ReportName") Is Nothing Then
reportDocument1.Load(Application("CrystalReportsPath") & Request.QueryString("ReportName"))
End If
Case Else
If Not Request.QueryString("ReportName") Is Nothing And Not Request.QueryString("Database") Is Nothing Then
Dim oDBinfo As DatabaseInformation = GetDatabaseInformation(Request.QueryString("Database"), Application("SettingsXml"))
Dim oTblInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim crTableLogonInfos As CrystalDecisions.Shared.TableLogOnInfos = New CrystalDecisions.Shared.TableLogOnInfos
reportDocument1.Load(Application("CrystalReportsPath") & Request.QueryString("ReportName"))
oDBinfo.UserID = Decrypt(oDBinfo.UserID, Application("BankersKey"))
oDBinfo.Password = Decrypt(oDBinfo.Password, Application("BankersKey"))
SvrName = oDBinfo.ServerName
DbName = Regex.Match(oDBinfo.ConnectionString, "(initial catalog=\w{2,};)").Value
DbName = DbName.Replace("initial catalog=", "").Trim.Trim(";")
For Each rpt In reportDocument1.Subreports
For Each oTable In rpt.Database.Tables
oLogonInfo = oTable.LogOnInfo
With oLogonInfo.ConnectionInfo
.ServerName = SvrName
.DatabaseName = DbName
.UserID = oDBinfo.UserID
.Password = oDBinfo.Password
oTable.ApplyLogOnInfo(oLogonInfo)
oTblInfo = oLogonInfo
End With
Next
rpt.SetDatabaseLogon(oDBinfo.UserID, oDBinfo.Password, SvrName, DbName, True)
Next
rpt = reportDocument1
For Each oTable In rpt.Database.Tables
oLogonInfo = oTable.LogOnInfo
With oLogonInfo.ConnectionInfo
.ServerName = SvrName
.DatabaseName = DbName
.UserID = oDBinfo.UserID
.Password = oDBinfo.Password
oTable.ApplyLogOnInfo(oLogonInfo)
oTblInfo = oLogonInfo
End With
Next
reportDocument1.SetDatabaseLogon(oDBinfo.UserID, oDBinfo.Password, SvrName, DbName, True)
'crTableLogonInfos.Add(oTblInfo)
'CrystalReportViewer1.LogOnInfo = crTableLogonInfos
End If
' Testing for the existance of QueryString Parameters
For Each tmpStr In Request.QueryString.Keys
If tmpStr.StartsWith("p") Then
rpt.SetParameterValue(CType(tmpStr.TrimStart("p"), Integer), Request.QueryString.Item(tmpStr))
End If
Next
For Each tmpStr In Request.QueryString.Keys
If tmpStr.ToLower = "export" Then
Select Case Request.QueryString.Item(tmpStr).ToLower
Case "pdf"
ExportAs(rpt, CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat)
Case "xls"
ExportAs(rpt, CrystalDecisions.[Shared].ExportFormatType.Excel)
Case "doc"
ExportAs(rpt, CrystalDecisions.[Shared].ExportFormatType.WordForWindows)
Case "rtf"
ExportAs(rpt, CrystalDecisions.[Shared].ExportFormatType.RichText)
End Select
Exit Sub
End If
Next
End Select
CrystalReportViewer2.ReportSource = reportDocument1
CrystalReportViewer2.PrintMode = CrystalDecisions.Web.PrintMode.Pdf
Catch ex As Exception
LogError(ex, MethodInfo.GetCurrentMethod.Name)
Finally
If Not rpt Is Nothing Then
rpt.Dispose()
rpt = Nothing
End If
oLogonInfo = Nothing
If Not oTable Is Nothing Then
oTable.Dispose()
oTable = Nothing
End If
If Not reportDocument1 Is Nothing Then
reportDocument1.Dispose()
reportDocument1 = Nothing
End If
End Try
End Sub