使用rs.exe在报表服务器上运行参数报表

时间:2015-10-05 16:16:09

标签: vb.net web-services batch-file vbscript reportingservices-2005

当我尝试运行rs.exe来运行我的报告(带参数)时,我遇到了这种情况。

我在下面使用这个bat脚本:

"\\server\R\subfolder\working\app\rs.exe" -i \\server\R\subfolder\working\inputfile\coo.rss -s "http://server/ReportServer_MSSQLSERVER2" -v FILENAME="\\server\R\subfolder\working\inputfile\file.csv" -v REPORTSERVER_FOLDER="/FILE_REPORT/FILE" -v Inputfile='DocType' -t  -v FORMAT="EXCEL" -e Exec2005

在上面的bat脚本(名称为coo.bat)中,我硬编码了报告参数(isInputfile ='DocType),然后我在下面的报告服务脚本中引用了它:

 Public Sub Main()

 Dim separators As String = " "
 Dim Commands As String = Microsoft.VisualBasic.Command()
 DIm inputid As string
 Dim args() As String = Commands.Split(separators.ToCharArray)
 Dim argcount As Integer = 0
 For Each x As String In args
 argcount += 1
 Next
inputid = args(0).ToUpper

    TRY

     DIM deviceInfo as string = Nothing
     DIM extension as string = Nothing
     DIM encoding as string
     DIM mimeType as string = "application/Excel"
     DIM warnings() AS Warning = Nothing
     DIM streamIDs() as string = Nothing
     DIM results() as Byte

     rs.Credentials = System.Net.CredentialCache.DefaultCredentials
     rs.LoadReport(REPORTSERVER_FOLDER, inputid)

     results = rs.Render(FORMAT, deviceInfo, extension, mimeType, encoding, warnings, streamIDs)

     DIM stream As FileStream = File.OpenWrite(FILENAME)
     stream.Write(results, 0, results.Length)
     stream.Close()

    Catch e As IOException
      Console.WriteLine(e.Message)
    End Try
End Sub

但是,每当我执行coo.bat时,我都会得到:Unhandled exception:The parameter value provided for 'snapshotID' does not match the parameter type.

我将非常感谢您的投入。

1 个答案:

答案 0 :(得分:1)

我终于找到了解决方案。请参阅编辑过的代码

Public Sub Main()

 Dim separators As String = " "
 Dim Commands As String = Microsoft.VisualBasic.Command()
 Dim args() As String = Commands.Split(separators.ToString)
'Report Parameters
 Dim parameters(1) As ParameterValue
 parameters(0) = New ParameterValue()
 parameters(0).Name = "Inputfile"
 parameters(0).Value =Inputfile


    TRY
     DIM historyID as string = Nothing
     DIM deviceInfo as string = Nothing
     DIM extension as string = Nothing
     DIM encoding as string
     DIM mimeType as string = "application/Excel"
     DIM warnings() AS Warning = Nothing
     DIM streamIDs() as string = Nothing
     DIM results() as Byte

     rs.Credentials = System.Net.CredentialCache.DefaultCredentials
     rs.LoadReport(REPORTSERVER_FOLDER,historyID )
     rs.SetExecutionParameters(parameters, "en-us")
     results = rs.Render(FORMAT, deviceInfo, extension, mimeType, encoding, warnings, streamIDs)

     DIM stream As FileStream = File.OpenWrite(FILENAME)
     stream.Write(results, 0, results.Length)
     stream.Close()

    Catch e As IOException
      Console.WriteLine(e.Message)
    End Try
End Sub