【问题标题】:SSRS and powershell: Parameter not acceptedSSRS 和 powershell:不接受参数
【发布时间】:2016-03-22 14:02:35
【问题描述】:

我使用 Powershell 在 Microsoft SQL Report Services 上运行多个报告并将结果保存到 Word 文档。我有一个脚本,其中包含处理与报表服务器通信的函数:

## File "qrap-functions.ps1"
function GetRSConnection($server, $instance)
{
    $User = "xxxx"
    $PWord = ConvertTo-SecureString -String "yyyy" -AsPlainText -Force
    $c = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

    $reportServerURI = "http://" + $server + "/" + $instance + "/ReportExecution2005.asmx?WSDL"

    $RS = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $reportServerURI -Credential $c
    $RS.Url = $reportServerURI
    return $RS
}
function GetReport($RS, $reportPath)
{
    $reportPath = "/" + $reportPath
    #$reportPath
    $Report = $RS.GetType().GetMethod("LoadReport").Invoke($RS, @($reportPath, $null))      
    $parameters = @()
    $RS.SetExecutionParameters($parameters, "nl-nl") > $null
    return $report
}
function AddParameter($params, $name, $val)
{
    $par = New-Object RS.ParameterValue
    $par.Name = $name
    $par.Value = $val
    $params += $par
    return ,$params
}
function GetReportInFormat($RS, $report, $params, $format, $saveas)
{
    $deviceInfo = "<DeviceInfo><NoHeader>True</NoHeader></DeviceInfo>"
    $extension = ""
    $mimeType = ""
    $encoding = ""
    $warnings = $null
    $streamIDs = $null

    $RS.SetExecutionParameters($params, "nl-nl") > $null

    $RenderOutput = $RS.Render($format,
        $deviceInfo,
        [ref] $extension,
        [ref] $mimeType,
        [ref] $encoding,
        [ref] $warnings,
        [ref] $streamIDs
    )
    $Stream = New-Object System.IO.FileStream($saveas), Create, Write
    $Stream.Write($RenderOutput, 0, $RenderOutput.Length)
    $Stream.Close()
}

然后,我有一个脚本来执行包含财务季度数据的报告。该脚本运行良好:

## File "qrap-financieel.ps1"
. "./qrap-functions.ps1"

$saveas = "e:\test\financieel.doc"
$RS = GetRSConnection -server "MSZRDWH" -instance "reportserver_acc"
$report = GetReport -RS $RS -reportPath "kwartaalrapportage/kwartaalrapportage financieel"
$params = @()   
$kwartaal = "[Periode Maand].[Jaar Kwartaal].&[2015-2]"
$kptc = "[Kostenplaats].[Team code].&[2003]"

$params = AddParameter -params $params -name "PeriodeMaandJaarKwartaal" -val $kwartaal
$params = AddParameter -params $params -name "KostenplaatsTeamcode" -val $kptc

GetReportInformat -RS $RS -report $report -params $params -format "WORD" -saveas $saveas

$kwartaal$kptc 的值在此处是硬编码的,但在此脚本的实际版本中是参数。除了财务季度,我们还有其他三个季度报告需要通过此脚本输出。 其中两个运行良好,在第四个中我似乎无法正确设置其中一个参数。该脚本是:

## File "qrap-zorglog.ps1"
. "./qrap-functions.ps1"
$RS = GetRSConnection -server "MSZRDWH" -instance "reportserver_acc"
$report = GetReport -RS $RS -reportPath "kwartaalrapportage/kwartaalrapportage zorglogistiek"

$s = "Urologie"
$saveas = "e:\test\ZL Urologie.doc"
$params = @()   
$kwartaal = "[Periode Maand].[Jaar Kwartaal].&[2015-2]" 

$params = AddParameter -params $params -name "HoofdspecialismeSpecialismeOms"                       -val "[Hoofdspecialisme].[Specialisme Oms].&[$s]"
$params = AddParameter -params $params -name "PeriodeMaandJaarKwartaal"                             -val $kwartaal
$params = AddParameter -params $params -name "WachttijdenSpecialismeSpecialisme"                    -val "[Wachttijden Specialisme].[Specialisme].&[$s]"
$params = AddParameter -params $params -name "SpecialisatieGroeperingSpecialisatieGroeperingOms"    -val "[Specialistie Groepering].[Specialistie Groepering Oms].&[$s]"    
$params = AddParameter -params $params -name "AanvragendSpecialismeSpecialismeOms"                  -val "[AanvragendSpecialisme].[Specialisme Oms].&[$s]"

GetReportInformat -RS $RS -report $report -params $params -format "WORD" -saveas $saveas

当我执行这个脚本时,我得到这个错误:

Exception calling "Render" with "7" argument(s): "System.Web.Services.Protocols.SoapException: This report requires a 
default or user-defined value for the report parameter 'HoofdspecialismeSpecialismeOms'. To run or subscribe to this 
report, you must provide a parameter value. ---> Microsoft.ReportingServices.Diagnostics.Utilities.ReportParameterValueNot
SetException: This report requires a default or user-defined value for the report parameter 
'HoofdspecialismeSpecialismeOms'. To run or subscribe to this report, you must provide a parameter value.

我显然确实为“HoofdspecialismeSpecialismeOms”提供了一个值;我之前注意到,当参数不是预期的格式时,也会引发此错误。这种格式,由于 报告过滤器基于 SSAS 多维数据集中的层次结构,如下所示:[hierarchy].[sub-level].&amp;[member]。我已确保 [Hoofdspecialisme].[Specialisme Oms].&amp;[$s] 是正确的格式 在填充 SSRS 提示的查询中查找它。报表在通过 SSRS 运行时会显示数据 - 并从提示中获取参数。

我确实注意到这个参数允许多选。但是,我不认为这会导致错误,因为 AanvragendSpecialismeSpecialismeOms 也是如此。

知道为什么在调用GetReportInformat 时无法将这个参数输入到报告中吗?

【问题讨论】:

  • 我对 Powershell 的工作不多,但您是否尝试过参数之间没有多余的空格?它是用空格分隔的。
  • @HannoverFist 我刚刚尝试在-name-val 参数之间没有额外空格和制表符的情况下运行脚本,但没有运气。我仍然得到同样的错误。按参数顺序移动HoofdspecialismeSpecialismeOms 也不会改变。
  • @Matt 你说得对$q。在我的脚本中,这是一个参数。 Write-Host 告诉我这完全按照我的意愿得到解决。我已编辑问题以修复此值。该脚本确实有一个$s 的定义,但它是“Urologie”。
  • 如果更改参数顺序,该条目是否仍会显示错误?
  • @Matt 是的,更改顺序对错误消息没有影响。我知道参数之间可能存在交叉依赖关系,但这不适用于此处。

标签: powershell reporting-services


【解决方案1】:

你试过了吗

function AddParameter($params, $name, $val)
{
    $par = New-Object RS.ParameterValue
    $par.Name = $name
    $par.Value = $val
    $params += $par
    return ,$params
    #      ^Removing this comma?
}

除了为您的参数显式声明数据类型之外?

function AddParameter([Array]$params, [String]$name, [String]$val)
{
    $par = New-Object RS.ParameterValue
    $par.Name = $name
    $par.Value = $val
    $params += $par
    return ,$params
}

此外,由于有这么多用户定义的辅助函数调用导入的类型,这些类型调用方法并将属性设置为我们看不到的报表,因此很难帮助您深入解决这个特定报表的问题出现错误。看起来您已经尝试按顺序移动线路,在我看来,您可能对特定报告如何解析您通过 RS.ParameterValue 输入的值有疑问,所以也许看看它是否接受您的字符串在-val 中为您的AddParameter 用户定义函数设置。

编辑:

来自https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e38b4a34-c780-43bb-8321-15f96d0938a9/exception-calling-render-systemwebservicesprotocolssoapexception-one-or-more-data-source?forum=sqlreportingservices

当您尝试运行其中一个或多个数据源设置为“提示”凭据的报告时,会生成此错误。这意味着我们不会自动使用您的 Windows 凭据,而是您需要提供一组不同的凭据,这些凭据仅用于数据源。

听起来您可能需要搁置脚本并检查报告是否不同。

【讨论】:

  • AddParameters 中的逗号非常有必要。没有它,参数列表将仅转换为其第一个元素,并且在第二次传递时 +=operator 失败,因为它对于 RS.Parameter 对象无效。此外,使用(和填充)HoofdspecialismeSpecialismeOms 的查询数据源的配置与此报告和批处理中的其他数据源中使用的其他数据源相同。凭据在 GetRSConnection 函数中提供给报表服务器。
【解决方案2】:

我终于弄明白了:失败的提示启用了多选。在填写多选时,SSRS 需要一个值列表。当只给定一个字符串时,忽略该字符串并假定参数为空。

要给它一个列表,我们必须这样做:

$multival = New-Object System.Collections.Specialized.StringCollection
$multival.Add("[Hoofdspecialisme].[Specialisme Oms].&[$s]")
[snip]
$params = AddParameter -params $params -name "HoofdspecialismeSpecialismeOms" -val $multival

通过这个问题找到了答案: How to pass multiple value parameter to reporting services report via powershell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 2016-05-27
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多