本文介绍了在 ReportExecution2005.asmx SSRS 服务上调用 Render 方法时,snapshotID 参数类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在带有 MSSQL 2012 后端的 SSRS 2012 服务器上使用 ReportExecution2005.asmx 服务端点将报告呈现为 PDF.当我在 Web 服务上调用 Render 方法时,出现以下错误:为snapshotID"提供的参数值与参数类型不匹配.---> Microsoft.ReportingServices.Diagnostics.Utilities.ParameterTypeMismatchException:为snapshotID"提供的参数值与参数类型不匹配.---> System.FormatException: String 未被识别为有效的 DateTime

I am trying to render reports as PDF using the ReportExecution2005.asmx service endpoint on a SSRS 2012 server with MSSQL 2012 backend. When I call the Render method on the web service, I get the following error:The parameter value provided for 'snapshotID' does not match the parameter type. ---> Microsoft.ReportingServices.Diagnostics.Utilities.ParameterTypeMismatchException: The parameter value provided for 'snapshotID' does not match the parameter type. ---> System.FormatException: String was not recognized as a valid DateTime

我尝试呈现的任何报告都会发生此错误,snapshotID 不是报告上的参数,并且检查报告的配置,它们未设置为缓存或使用快照.我们最近刚刚从 MSSQL 2005 迁移到 2012,使用带有 SSRS 和 SQL 2005 的 ReportExecution2005 端点我从未见过此错误,它运行良好.我已经尝试将 snapshotID 添加为具有不同值(例如空字符串、当前时间等)的参数,但这显然不是它想要的.下面是我用来设置和调用服务上的 Render 方法的代码.在我的情况下 pstrExportFormat 将是PDF"

This error occurs with any report I try to render, snapshotID is not a parameter on the reports, and checking the configuration of the reports, they are not set up to be cached or use snapshots. We just recently moved from MSSQL 2005 to 2012, using the ReportExecution2005 endpoint with SSRS and SQL 2005 I never saw this error, it worked fine. I've tried adding snapshotID as a parameter with different values such as empty string, current time, etc. but that's apparently not what it's looking for. Below is the code I'm using to set up and call the Render method on the service. pstrExportFormat in my case will be "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 方法也不同.

Some additional information, this code is from an app built in VS 2012 Pro and targets the .NET 2.0 framework. I have tried targeting a newer framework but that gives me a different ReportExecutionService object altogether and I can't assign credentials in the same way, the Render method is also different in that case.

关于解决方法或以编程方式呈现报告的更好方法的任何想法?谢谢.

Any ideas on a workaround, or a better way to render reports programmatically? Thanks.

推荐答案

我今天遇到了完全相同的问题,并发现在 LoadReport 方法中,您希望确保 HistoryID 的值为 Nothing(在 C# 中为 null).现在,您使用空字符串传入它 - 将声明更改为

I had this exact same problem today and figured out that, in the LoadReport method, you want to make sure the HistoryID has a value of Nothing (null in C#). Right now, you're passing it in with an empty string - change the declaration to

  Dim lstrHistoryId As String = Nothing

或者将您的方法调用更改为

Or change your method call to

rs.LoadReport(pstrReportPath, Nothing)

这篇关于在 ReportExecution2005.asmx SSRS 服务上调用 Render 方法时,snapshotID 参数类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 05:33