我正在尝试使用具有 MSSQL 2012 后端的 SSRS 2012 服务器上的 ReportExecution2005.asmx 服务端点将报告呈现为 PDF。当我在 Web 服务上调用 Render 方法时,出现以下错误:
为“snapshotID”提供的参数值与参数类型不匹配。 ---> Microsoft.ReportingServices.Diagnostics.Utilities.ParameterTypeMismatchException:为“snapshotID”提供的参数值与参数类型不匹配。 ---> System.FormatException:字符串未被识别为有效的日期时间
我尝试呈现的任何报告都会发生此错误,snapshotID 不是报告上的参数,并且检查报告的配置,它们未设置为缓存或使用快照。我们最近刚刚从 MSSQL 2005 迁移到 2012,将 ReportExecution2005 端点与 SSRS 和 SQL 2005 一起使用,我从未见过此错误,它工作得很好。我尝试添加 snapshotID 作为具有不同值(例如空字符串、当前时间等)的参数,但这显然不是它想要的。下面是我用来设置和调用服务的 Render 方法的代码。在我的例子中,pstrExportFormat 将为“PDF”
Public Function ExportReport(pstrReportPath As String, plstParams As List(Of ReportParameter), pstrExportFormat As String) As Byte()
Dim lResults() As Byte = Nothing
Dim lstrSessionId As String
Dim execInfo As New reporting.ExecutionInfo
Dim execHeader As New reporting.ExecutionHeader
Dim lstrHistoryId As String = String.Empty
Try
Dim rs As New reporting.ReportExecutionService
Dim deviceInfo As String = "<DeviceInfo><PageHeight>8.5in</PageHeight><PageWidth>11in</PageWidth><MarginLeft>0.25in</MarginLeft><MarginRight>0.25in</MarginRight><MarginTop>0.25in</MarginTop><MarginBottom>0.25in</MarginBottom></DeviceInfo>"
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim params As New List(Of reporting.ParameterValue)
Dim param As reporting.ParameterValue
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
For Each lInputParam In plstParams
param = New reporting.ParameterValue
param.Name = lInputParam.Name
param.Value = lInputParam.Value
params.Add(param)
Next
rs.ExecutionHeaderValue = execHeader
execInfo = rs.LoadReport(pstrReportPath, lstrHistoryId)
rs.SetExecutionParameters(params.ToArray, "en-us")
lResults = rs.Render(pstrExportFormat, deviceInfo, "", "", "", Nothing, Nothing)
Catch ex As Exception
Throw
End Try
Return lResults
结束功能
一些附加信息,此代码来自 VS 2012 Pro 中内置的应用程序,面向 .NET 2.0 框架。我尝试过针对较新的框架,但这给了我一个完全不同的 ReportExecutionService 对象,并且我无法以相同的方式分配凭据,在这种情况下,Render 方法也不同。
关于解决方法的任何想法,或者以编程方式呈现报告的更好方法?谢谢。