问题描述
很难让 ReportViewer 控件运行具有可选 (NULL) 参数的报告。
报告直接在浏览器中的 SSRS 上运行良好,但是当我尝试在 ASP NET WebForm 应用程序中运行它们时,如果可选参数设置为空(空复选框被取消),我会收到空引用错误。
我收到此(误导性)StackTrace 消息:在 icrosoft.ReportingServices.Common.DateTimeUtil.ParseDatetoDefaultFormat => 似乎这是一些日期解析问题,但参数是整数、字符串(不需要日期时间解析)。>
我在 SSRS 2017 中使用 Microsoft.ReportViewer.WebForms,Version=15.0.0.0,示例应用程序是使用以下官方文档构建的:https://docs.microsoft.com/en-us/sql/reporting-services/application-integration/integrating-reporting-services-using-reportviewer-controls-get-started?view=sql-server-ver15
解决方法
升级到 nuget 包的 150.1427.0 版本后,我遇到了同样的问题。当我将 int 或 datetime 值作为参数传递时出现
异常:System.NullReferenceException:未将对象引用设置为对象的实例。
在 Microsoft.ReportingServices.Common.DateTimeUtil.ParseDateToDefaultFormat(String strDateTime,CultureInfo formatProvider)
在 Microsoft.Reporting.WebForms.ServerReport.SetParameters(IEnumerable`1 参数)
根据发行说明,他们“修复了影响某些语言环境的日期时间解析问题”。 https://docs.microsoft.com/en-us/sql/reporting-services/application-integration/release-notes-ssrs-application-integration?view=sql-server-ver15
所以我降级到 150.1404.0 版本,问题就解决了
,如果您升级到版本 150.1449.0(或更高版本),则会解决导致此错误的错误。