Before I start here is my platform:
- Visial Studio 2008 version 3.5 SP1
- The code behind is Visual Basic.NET
- The app was written using the .Net Framework 2.0
- Crystal Reports (not sure of the version)
- Windows Vista
- SQL Server 2005 running on a Windows 2008 (not R2) box
The web server platform:
- Windows 2003
- IIS 6.0
- Crystal Reports (also not sure of the version)
- .Net Framework 2.0
A user is reporting an error to an application that was written by a previous developer who is no longer here. I have inherited his code. I did see the app work a few weeks ago but prior to that and right now when the user goes to print the report into a PDF file I get an ASP error that looks like this:
Server Error in '/MyApplication' Application.
Object reference not set to an instance of an object.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] MyApplication.libMyAppFunctions.ExportAndDisplayPDF(Object objTemp) in O:\MyApplication\library\libMyAppFunctions.vb:499 MyApplication.ViewReport.btnPrint_Click(Object sender, EventArgs e) in O:\MyApplication\aspx\Reports\ViewReport.aspx.vb:1454 System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 |
Version Information: Microsoft .NET Framework Version:2.0.50727.3643; ASP.NET Version:2.0.50727.3634
This code works perfectly in VS on my local machine. The problem only happens on the web server and when I said that I have seen it work in the past I was speaking of seeing it work on the web server.
Here is the VB.Net code:
Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click Dim d Dim objViewReport As ViewReport = New ViewReport(frmView) dtReportComments = objViewReport.getDtReportComments Dim oRpt As Object If (objViewReport.intTimeOfDayID <> -1) Then oRpt = New rptTOC_DateSpecific() Else oRpt = New rptTOC_DateAll() End If oRpt.SetDataSource(dtReportComments) ''set Season, date and TimeOfDay Dim toSeason As CrystalDecisions.CrystalReports.Engine.TextObject = oRpt.ReportDefinition.ReportObjects.Item("txtSeason") Dim toTitle As CrystalDecisions.CrystalReports.Engine.TextObject = oRpt.ReportDefinition.ReportObjects.Item("txtViewReportDate") Dim toTimeOfDay As CrystalDecisions.CrystalReports.Engine.TextObject = oRpt.ReportDefinition.ReportObjects.Item("txtTimeOfDay") toSeason.Text = objViewReport.strSeasonID If (objViewReport.intTimeOfDayID <> -1) Then toTitle.Text = objViewReport.datViewReportDate.ToString("MM/dd/yyyy") toTimeOfDay.Text = objViewReport.strTimeOfDay Else toTitle.Text = "All" toTimeOfDay.Text = "All" End IfExportAndDisplayPDF(oRpt) End Sub
And
Public Function ExportAndDisplayPDF(ByVal objTemp As Object) Dim dNow As DateTime = Now Dim strFileName As String = dNow.Ticks & ".pdf" ''write to a pdf file. Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions() objTemp.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile objTemp.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat DiskOpts.DiskFileName = HttpContext.Current.Request.PhysicalApplicationPath.ToString & "ReportOutput" & strFileName objTemp.ExportOptions.DestinationOptions = DiskOpts Try objTemp.Export() Catch oRptExcept As Exception HttpContext.Current.Response.Write(oRptExcept.Message & "<br><br>" & oRptExcept.InnerException.Message) End Try HttpContext.Current.Response.Redirect("/MyApplication/aspx/print/Print.aspx?theDestination=" & strFileName) End Function
There are a couple things that might be causing the problem that I have identified but I am not sure how or even if these concerns need resolving.
- In the error the 2 lines at the top of the stack point to the O: drive where the file is located. The problem is the O: drive is only accessible to my local computer and not the web server. I cannot imagine that compling and publishing a web app from
my local machine to the web server would copy the original paths to the files and expect the web server to use that path. That seems a little bit wrong to me.
Does anyone know if that is a problem and if it is then how do I go about resolving this issue? - 2. In the Object Browser in the Solution for the app in Visual Studio the path to CrystalDecisions.CrystalReports.Engine is:
C:\Program Files\Business Objects\Common\2.8\managed\CrystalDecisions.CrystalReports.Engine.dll
This path works on my local drive but on the web server the path is a little different. Everything is the same in the path exceptmanaged is replaced by bin. There is no managed folder on the web server.
Is this a problem?
If those 2 issues are not the problem then I am at a total loss at this point and any help would be greatly appreciated.