我的代码在Web表单页面上设置ServerReport对象,然后将报告从SSRS呈现为pdf。参数和报告名称由URL传递。
Private Sub Page_Load(sender As Object, e As EventArgs)
Dim reportname As String
'Dim parameter(0) As ReportParameter
reportname = Request("reportname").ToString
Dim v As New ReportViewer
v.ProcessingMode = ProcessingMode.Remote
Dim serverreport As New ServerReport
serverreport = v.ServerReport
serverreport.ReportServerUrl = New Uri("http://xxxxxx:80/ReportServer")
serverreport.ReportPath = "/Reports/Aramid/Sheeter/" & reportname
Select Case reportname
Case Is = "NomexBlockCard" 'Or "NomexBlockLabel" Or "NomexInternalLabel"
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("paramBlock", Request("paramBlock").ToString, False))
serverreport.SetParameters(paramList)
Case Is = "NomexRoutingData"
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("paramWO", Request("paramWO").ToString, False))
serverreport.SetParameters(paramList)
End Select
serverreport.ReportServerCredentials = New ReportViewerCredentials(user name here, password here, "CORE")
Save(serverreport, "C:\WebReports\" & reportname & ".pdf")
'now print
Response.Redirect("reports.ashx?fileName=" & reportname)
End Sub
Public Sub Save(ByVal sr As ServerReport, ByVal savePath As String)
Try
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim deviceInfo As String
Dim bytes As Byte()
deviceInfo = "True" '<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
bytes = sr.Render("PDF", Nothing, mimeType, _
encoding, extension, streamids, warnings)
Using Stream As New FileStream(savePath, FileMode.Create)
Stream.Write(Bytes, 0, Bytes.Length)
Stream.Close()
End Using
Catch ex As Exception
End Try
End Sub
报告呈现并保存为pdf,但参数值似乎未在报告中使用。
我已经一遍又一遍地确认paramBlock中有一个值。
我不知道自己做错了什么。
我错过了一步还是什么?
赖安
答案 0 :(得分:4)
在呈现和保存报告时,我假设凭据设置正确。
您可以在保存报告之前使用 ServerReport.GetParameters 功能来检查参数(及其值/属性)实际是什么。
此外,请确保您设置报告所需的每个parameter(即使是那些隐藏或内部的),并且每个参数值都在参数的allowed values范围内(如果设置了限制) )。
如果问题不在于传递参数,您可能需要查看报告本身及其处理参数的方式。
答案 1 :(得分:3)
根据您最近关于“参数验证失败”错误的评论,听起来您的问题不在于您的调用代码结构,而是将参数与报告定义相匹配。
最常见的问题是您忽略的隐藏或内部参数。您需要仔细检查SSRS报告设计器中的参数设计,并确保您传递的参数符合预期。
答案 2 :(得分:2)
考虑以下建议。它可能有助于您解决问题。在考虑了每一点后,您可以尝试使用代码
将以下代码放在 Select Case reportname statement 行的正上方 serverreport.ReportServerCredentials =新的ReportViewerCredentials(此处为用户名,此处为密码,“CORE”)
您也可以尝试更改代码行 serverreport.ReportServerCredentials =新的ReportViewerCredentials(此处为用户名,此处为密码,“CORE”)
要
ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials
答案 3 :(得分:2)
您可以尝试以下代码:
Private Sub Page_Load(ByVal sender As Object,ByVal e As EventArgs) Dim reportname As String = Request(“reportname”)。ToString 'Dim参数(0)As ReportParameter
Dim v As New ReportViewer
v.ProcessingMode = ProcessingMode.Remote
Dim ServerReport As ServerReport
ServerReport = v.ServerReport
serverreport.ReportServerUrl = New Uri("http://xxxxxx:80/ReportServer")
serverreport.ReportPath = "/Reports/Aramid/Sheeter/" & reportname
ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials
Select Case reportname
Case Is = "NomexBlockCard" 'Or "NomexBlockLabel" Or "NomexInternalLabel"
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("paramBlock", Request("paramBlock").ToString, False))
serverreport.SetParameters(paramList)
Case Is = "NomexRoutingData"
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("paramWO", Request("paramWO").ToString, False))
serverreport.SetParameters(paramList)
End Select
Save(serverreport, "C:\WebReports\" & reportname & ".pdf")
End Sub
Public Sub Save(ByRef sr As ServerReport, ByVal savePath As String)
Try
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim deviceInfo As String
Dim bytes As Byte()
deviceInfo = "True" '<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
bytes = sr.Render("PDF", Nothing, mimeType, _
encoding, extension, streamids, warnings)
Using Stream As New FileStream(savePath, FileMode.Create)
Stream.Write(bytes, 0, bytes.Length)
Stream.Close()
End Using
Catch ex As Exception
End Try
End Sub
答案 4 :(得分:2)
可能情况并非如此,但我记得在Parameters
期间可能会丢失PostBack
值。
所以我会尝试这样的语法:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.Page.IsPostBack Then
'your code to setup and print report
End If
End Sub
如果此解决方案不起作用,请提供Report Definition
中使用的代码。