Wednesday, March 7, 2012

Parameters ignored, Render report from VB .Net application

I seem to be unable to pass parameters from a VB .Net application to Reporting Services.

Before I added the parameters to the query, I got all the rows back. So I know the application is basically working. Now that I have added the parameters, I get nothing.

I thought the SetExecutionParameters function would help, but my syntax is wrong and it fails.

I would appreciate any hint as to what step I am missing.


Report setup:

Parameters

Name Value
@.Report =Parameters!Report.Value
@.Corp =Parameters!Corp.Value
@.Dept =Parameters!Dept.Value

Query conditions

WHERE Report = 'BudgetVarianceSummary'
AND PeriodEnd = CONVERT(DateTime,CONVERT(char,GETDATE()- DATEPART(day,GETDATE()),112))
AND Report = @.Report
AND Corp = @.Corp
AND Dept = @.Dept

VB Code snippet:

Dim reportPath As String = "/FinancialReports/BudgetVarianceSummary"
Dim format As String = "PDF"

' Prepare report parameter.
Dim parameters(3) As ParameterValue
parameters(0) = New ParameterValue()
parameters(0).Name = "Report"
parameters(0).Value = "BudgetVarianceSummary"
parameters(1) = New ParameterValue()
parameters(1).Name = "Corp"
parameters(1).Value = "10"
parameters(2) = New ParameterValue()
parameters(2).Name = "Dept"
parameters(2).Value = "7255"


Dim execInfo As New ExecutionInfo
Dim execHeader As New ExecutionHeader()
Dim SessionId As String
Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader
execInfo = rs.LoadReport(reportPath, historyID)

'This line of code fails
'rs.SetExecutionParameters(parameters, "en-us")

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

Dim DateiName As String = Benutzer.Benutzer & "_" & Date.Now.ToString("yyMMdd_HHMMss") & ".pdf"

Dim rs As New ReportingServices.ReportExecutionService

Dim Info As New ReportingServices.ExecutionInfo

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim parameters(1) As ReportingServices.ParameterValue

parameters(0) = New ReportingServices.ParameterValue()

parameters(0).Name = "KB"

parameters(0).Value = _KB

parameters(1) = New ReportingServices.ParameterValue()

parameters(1).Name = "KBG"

parameters(1).Value = CStr(_IDKBG)

Info = rs.LoadReport("/SOR/KBGDruck10", Nothing)

rs.SetExecutionParameters(parameters, "de-ch")

Dim results() As Byte

results = rs.Render("PDF", "", "", "", "", Nothing, Nothing)

Dim Stream As System.IO.FileStream = System.IO.File.OpenWrite(DateiName)

Stream.Write(results, 0, results.Length)

Stream.Close()

Windows.Forms.Cursor.Current = Cursors.Default

Try

Diagnostics.Process.Start(DateiName)

Catch ex As Exception

End Try

XInfo("", "")

No comments:

Post a Comment