早在我开始工作之前,开发人员就在VS 2008中的VB.Net中编写了一个Web应用程序,其中包含一个使用Crystal Reports创建报表的链接,作为PDF文件 . 用户向我报告该链接生成错误 . 我不确定这是否一直存在问题,现在只是报告或者服务器上是否有变化 . 这是一个我很少参与的应用程序,因为我来过这里并且编写它的开发人员早已离开公司 . 自90年代末以来,我一直没有使用Crystal Reports . 无论如何足够的背景是错误 .
我追踪到了objTemp.Export()方法调用(其中objTemp是Crystal Reports ReportClass类的实例化) .
当我在Visual Studio IDE中的本地计算机上本地运行应用程序时,一切都正常工作 . 我重新编译并将应用程序发布到 生产环境 服务器上的单独文件夹中,然后运行我的版本,我仍然得到与 生产环境 版本中相同的错误 .
ASP Error页面如下所示:
'/ MyApplication'应用程序中的
服务器错误 .
对象引用未设置为对象的实例 .
Description: 执行当前Web请求期间发生未处理的异常 . 请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息 .
Exception Details: System.NullReferenceException:未将对象引用设置为对象的实例 .
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:491
MyApplication.ViewReport.btnPrint_Click(Object sender, EventArgs e) in O:\MyApplication\aspx\Reports\ViewReport.aspx.vb:1462
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版本:2.0.50727.3643; ASP.NET版本:2.0.50727.3634
我遇到的一个问题是,在错误中它指向“O:\ MyApplication ...” . 那是我保存源代码的网络驱动器 . 没有O:驱动器映射到服务器 . 这似乎可能是错误的根源,但我无法想象硬编码驱动器号是Visual Studio开发环境的标准部分 . 它从未在我编写/工作的任何其他应用程序中引起此类问题 .
*已添加3/19/2013以回应Andrew对源代码的请求
这是在单击创建PDF文件的链接时调用的代码 .
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 If
ExportAndDisplayPDF(oRpt)
End Sub
这是btnPrint_click方法调用的代码
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
只是寻找解决方案 .
谢谢
罗伯特
2 回答
这个问题的答案与Crystal Reports完全无关 . 当您发送程序员(我)来执行网络管理员工作时会发生这种情况 . 好吧,我知道,你们中有很多人可以做到这两点,但我不是你们 . 我在网络方面经验很少 . 足够了 . 虽然是我虚弱的大脑才弄明白 .
应用程序的工作方式是将数据读入表中,然后将数据发送到Crystal Reports对象,以保存为全新的PDF文件 . 然后,在此之后,应用程序打开了新的PDF文件以供查看 . 错误抱怨该对象未实例化 . 对我来说,编程问题 .
这根本不是一个编程问题 . 正在创建新PDF文件的文件夹没有对网站运行的用户组的写许可权 .
如果您没有写入权限,如何创建PDF?如果您没有写入权限,如何创建PDF?
一个老问题,但最近几天我遇到了类似的问题 .
通用的“对象引用未设置...”非常具有误导性 . 像往常一样,发布的代码在DEV和QA环境中可以正常工作,并且在PRODUCTION中会失败 .
我将 objTemp.Export() 更改为 objTemp.ExportToHttpResponse(FileName, Response, false, "") ,它就像一个魅力 .
希望这有助于某人 .