简体   繁体   English

自动更改SQL Server报表的数据源

[英]Change data source for SQL Server Reports automatically

We have an ASP .NET MVC web application that links to some SQL Server Reporting Services reports. 我们有一个ASP .NET MVC Web应用程序,该应用程序链接到一些SQL Server Reporting Services报告。 Our web application uses one database for the morning (let's call this the "AM database") and a different database for the afternoon/night ("PM database"). 我们的Web应用程序在早上使用一个数据库(我们称其为“ AM数据库”),在下午/晚上使用另一个数据库(“ PM数据库”)。

We have a SQL Server Agent job set up that switches the connection string for the web application from the AM database to the PM database (or vice-versa) on a schedule. 我们有一个SQL Server Agent作业设置,可以按计划将Web应用程序的连接字符串从AM数据库切换到PM数据库(反之亦然)。 It works by copying/replacing the MVC application's Web.config file with the appropriate AM/PM version. 它通过使用适当的AM / PM版本复制/替换MVC应用程序的Web.config文件来工作。 This works as intended. 这按预期工作。

However, the reports will remain pointed to whichever database they were using previously, unless the data source is manually changed through SSRS. 但是,除非通过SSRS手动更改了数据源,否则报告将始终指向他们以前使用的哪个数据库。 These reports need to be updated to point to the same database as the MVC web app. 这些报告需要更新以指向与MVC Web应用程序相同的数据库。

How can I automate this process (preferably through SQL Server Agent)? 如何自动执行此过程(最好通过SQL Server Agent)? We need the reports to change their database connection on a regular interval. 我们需要报告定期更改其数据库连接。

This works for embedded connections I am not sure about shared data source references. 这适用于嵌入式连接,我不确定共享数据源引用。 Just add two parameters to your report for database name and database server name. 只需在报表中为数据库名称和数据库服务器名称添加两个参数。 You could also use codes or mask the names if you prefer not so send this info over the wire. 如果您不愿意,也可以使用代码或掩盖名称,以便通过网络发送此信息。

In your embedded data set add the following as your connectionstring 在嵌入式数据集中,将以下内容添加为连接字符串

expression:="Data Source="+Parameters!DatabaseServerName.Value+";Initial Catalog="&Parameters!DatabaseName.Value

Next, add a defined user for your credentials then all you need to do is pass in the two params for each report from your application. 接下来,为您的凭据添加一个已定义的用户,然后您要做的就是为应用程序中的每个报告传递两个参数。

NOTE: You need to add your defaults when designing to a server that is accessible. 注意:在设计到可访问的服务器时,需要添加默认值。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM