powershell - SSRS 和 powershell : Parameter not accepted

标签 powershell reporting-services

我使用 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].&[member]。我已确保 [Hoofdspecialisme].[Specialisme Oms].&[$s] 是正确的格式 在填充 SSRS 提示的查询中查找它。该报告在通过 SSRS 运行并从提示符中获取参数时确实会显示数据。

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

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

最佳答案

你试过吗

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 输入的值有疑问,所以也许看一下at 如果它接受您在 -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

This error is generated when you are attempting to run a report in which one or more of the data sources are set to "prompt" credentials. This means we do not use your Windows credentials automatically, but rather you need to supply a different set of credentials which are used only for the data source.

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

关于powershell - SSRS 和 powershell : Parameter not accepted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36156515/

相关文章:

string - 获取 .trim/-trim、.replace/-replace、.split/-split 和其他字符串运算符的帮助

json - Powershell - 解析不一致的 Json 数据

iis - 如何使用powershell远程配置IIS?

arrays - PowerShell 数组过滤器

reporting-services - 为报告查看器/报告管理器放置图标的位置

sql - Dynamics 365 CRM - 从 SSRS 报告中删除外部联接重复项

function - 编写等效的 powershell 脚本和函数的最佳实践

asp.net - ReportViewer - "Unable to serialize the session state. in ' stateserver' 和 'sqlserver' 模式

mysql - SSRS 报告数据库版本之间的被动性

reporting-services - 何时在 RDL 报告上使用 RDLC?