简体   繁体   English

在服务器端以编程方式更改报告的SSRS数据源

[英]Change SSRS data source of report programmatically in server side

Today, for each customer, we deploy same SSRS reports folder and data source folder. 今天,对于每个客户,我们部署相同的SSRS报告文件夹和数据源文件夹。 The difference between these folders are the name of each folder and the connection string of the data source. 这些文件夹之间的区别是每个文件夹的名称和数据源的连接字符串。

We are using Report Server 2008 R2. 我们正在使用Report Server 2008 R2。

Is it possible to maintain only one reports and data source folder and change programmatically its connection string on server-side before the report been rendered ? 在报表呈现之前,是否可以只维护一个报表和数据源文件夹并以编程方式更改其服务器端的连接字符串?

If not, Is it something that can be achieved by changing some logic in reports? 如果没有,是否可以通过更改报告中的某些逻辑来实现? Today we use "shared data source" option. 今天我们使用“共享数据源”选项。

This is something we've done in our environment - we maintain one set of reports that can be deployed at any client with their own configuration. 这是我们在我们的环境中所做的事情 - 我们维护一组报告,这些报告可以在任何具有自己配置的客户端上部署。

You've got a couple of options here. 你在这里有几个选择。 Since you're using a Shared Data Source this makes things easier as you won't need to define a Data Source for each report. 由于您使用的是共享数据源,因此您无需为每个报表定义数据源,因此更加轻松。

1. Use the rs.exe utility and a script file 1.使用rs.exe实用程序和脚本文件

rs.exe at Books Online 联机丛书中的rs.exe

This program allows you to create script files (in VB.NET) that can interact with a Report Server Web Service. 此程序允许您创建可与报表服务器Web服务交互的脚本文件(在VB.NET中)。 You create a script file (eg Deploy.rss) and call the rs.exe program with various parameters, including any custom ones you define: 您创建一个脚本文件(例如Deploy.rss)并使用各种参数调用rs.exe程序,包括您定义的任何自定义参数:

rs.exe -i DeployReports.rss -s http://server/ReportServer -v DatabaseInstance="SQL" -v DatabaseName="ReportDB" -v ReportFolder="ClientReports"

So this would call a script DeployReports.rss, connect to http://server/ReportServer , with three user defined parameters which could be used to create a data source and the report folder. 因此,这将调用脚本DeployReports.rss,连接到http://server/ReportServer ,其中包含三个用户定义的参数,可用于创建数据源和报告文件夹。

In the scipt file you could have something like this: 在scipt文件中你可以有这样的东西:

Public Sub Main()

    rs.Credentials = System.Net.CredentialCache.DefaultCredentials

    CreateFolder(reportFolder, "Report folder")
    CreateFolder(datasourceFolder, "Data source folder")
    CreateDataSource()

End Sub

Which can then make Web Service calls like: 然后,可以进行以下Web服务调用:

rs.CreateFolder(folderName, "/", Nothing)

'Define the data source definition.
Dim definition As New DataSourceDefinition()
definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated
definition.ConnectString = "data source=" + DatabaseInstance + ";initial catalog=" + DatabaseName
definition.Enabled = True
definition.EnabledSpecified = True
definition.Extension = "SQL"
definition.ImpersonateUser = False
definition.ImpersonateUserSpecified = True
'Use the default prompt string.
definition.Prompt = Nothing
definition.WindowsCredentials = False

Try

    rs.CreateDataSource(datasource, datasourcePath, False, definition, Nothing)
    Console.WriteLine("Data source {0} created successfully", datasource)

Catch e As Exception

    Console.WriteLine(e.Message)

End Try

You haven't specified what version of Reporting Services you're using, so I'm assuming 2008. Please note that there are multiple endpoints that can be used, depending on SQL Server version. 您尚未指定您正在使用的Reporting Services版本,因此我假设为2008.请注意,根据SQL Server版本,可以使用多个端点。 The 2005/2008 end point is deprecated in 2008R2 and above but is still usable. 2005/2008终点在2008R2及以上版本中被弃用,但仍可使用。 Just something to bear in mind when writing your script. 在编写脚本时要记住一些事情。

2. Call the SSRS Web Service through an application 2.通过应用程序调用SSRS Web服务

Report Server Web Service overview 报表服务器Web服务概述

The same calls that are made from the script above can be made in any other application, too. 从上面的脚本进行的相同调用也可以在任何其他应用程序中进行。 So you'd just need to add a reference to a Report Server Web Service through WSDL and you can connect to a remote service and call its methods to deploy reports, data sources, etc. 因此,您只需要通过WSDL添加对报表服务器Web服务的引用,您就可以连接到远程服务并调用其方法来部署报表,数据源等。

So ultimately you're connecting to the Report Server Web Service, it's just the medium used that you need to think about. 因此,最终您将连接到报表服务器Web服务,它只是您需要考虑的使用媒介。

Using a script is easier to get running as it's just running a program from the command line, but writing your own deployment application will certainly give greater flexibility. 使用脚本更容易运行,因为它只是从命令行运行程序,但编写自己的部署应用程序肯定会提供更大的灵活性。 I would recommend getting the script going, so you understand the process, then migrate this to a bespoke application if required. 我建议让脚本运行,以便您了解该过程,然后根据需要将其迁移到定制应用程序。 Good luck! 祝好运!

You can use an Expression Based Connection String to select the correct database. 您可以使用基于表达式的连接字符串来选择正确的数据库。 You can base this on a parameter your application passes in, or the UserId global variable . 您可以将其基于应用程序传入的参数或UserId全局变量 I do believe you need to configure the unattended execution account for this to work. 我确实认为你需要配置无人值守的执行帐户才能生效。

Note: be careful about the security implications . 注意:请注意安全隐患 Realize that if you would pass sensitive data (eg passwords) into a parameter, that (a) it will go over the wire, and (b) will be stored in the execution log tables for reporting services. 要意识到,如果您将敏感数据(例如密码)传递给参数,那么(a)它将通过线路传输,(b)将存储在执行日志表中以用于报告服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何动态更改SSRS报告数据源的连接类型 - How to change connection type of SSRS report Data source dynamically 以编程方式将SSRS数据源另存为.ds文件 - Save SSRS data source as .ds file programmatically SSRS以编程方式设置“凭据安全地存储在报表服务器中” - SSRS Set “Credentials stored securely in the report server” programmatically 如何从 SSRS 报告中获取数据源信息,使用 .NET - How to get the data source information from a SSRS report, using .NET 是否可以以及如何针对SQL Server中本地报告服务的在线Dynamics CRM数据源运行SSRS报告? - Is it possible and how to run an SSRS report against an online dynamics CRM data source from a local reporting service in SQL Server? 从IIS运行时,SSRS(Sql Server 2016)报告错误为“无法创建与数据源DSTEST的连接”。 (rsErrorOpeningConnection)' - SSRS(Sql Server 2016) Report error when running from IIS is 'Cannot create a connection to data source 'DSTEST'. (rsErrorOpeningConnection)' 以编程方式更改Exchange Server上的数据 - programmatically change data on Exchange Server 以编程方式在 C# 中将 SSRS 报告另存为 PDF - Save SSRS Report as PDF in C# programmatically 以编程方式将SSRS报告转换为Pdf定价问题 - Programmatically converted SSRS report to Pdf priting issue 数据源不支持服务器端数据分页 - The data source does not support server-side data paging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM