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
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
End Function
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With