views:

32

answers:

3

Hello all,

I have a single server that hosts our production and development databases. It's running SQL Server 2008 (not R2) with SQL Server Reporting Services.

I deploy a VS 2008 Reporting Services project to the server to provide the reports. All the reports use a single shared data source, currently pointing at the production database.

A background service elsewhere creates PDF reports via the web service interface to SSRS.

My question is, given this environment, is it possible to programatically change the data source to be used during execution via the web service so either the dev or production database is used by a report?

I don't want to modify the shared data source or the report definition, I just want to be able to set the name of the database before I execute the report and I can't see how this is possible.

The only "simple" solution I can see is to install another report server instance, which seems like overkill for what I want. I'm about to do this unless anyone has a cunning answer for me!

Cheers, Chris.

+2  A: 

Edit - another suggestion

Have the datasource in Visual Studio point to the development database. Have the deployed datasource point to the production database. Set the datasource to not overwrite existing datasources on deployment. This means all development in VS will be against the development database but when you deploy the report, it will use the previously deployed datasource that points to the production database.

Original suggestion

We have a similar issue - we have a suite of reports that need to be able to run on any of our databases for historical financial years so the user needs to be able to select which database to run the report for.

The strength of Reporting Services is that everything is an expression and the SQL for the data set is no different. What we do is modify the SQL to use the database as selected by the user.

It is set up as follows: On Sql Server in a common database we create a table called DatabaseLookup that has the fields DatabaseLabel (the display name) and DatabaseName (the actual name of the database) plus an INT SortOrder so we can order the databases sequentially backwards as we create a new one. In Reporting Services we create a datasource that points to our common database and a new dataset called Databases that uses that datasource:

SELECT DatabaseLabel, DatabaseName
FROM DatabaseLookup
ORDER BY SortOrder

A Parameter is set up called Database which uses the Databases dataset with Value field = DatabaseName and Label field = DatabaseLabel and the non-queried default to be our current database.

Now we modify the SQL for our main table of the report into an expression. Let's say our SQL looks like this:

SELECT SomeField, OtherField
FROM SomeTable

We turn that into a calculated expression, like so:

="SELECT SomeField, OtherField "
&"FROM " & Parameters!Database.Value & ".dbo.SomeTable "

The label of the database selected is also included in the header in a small font so people know what data they are looking at.

When a new financial year comes along, we simply add a new row to our DatabaseLookup table and every report in our system can now use that new database.

Chris Latta
Thanks Chris, it's useful to know other people are having the same problem and your solution is a good one. I have a slightly different scenario I think where most of my users are unaware of anything other than the production environment so I think I am still tending towards another SSRS instance at the moment. Cheers, Chris.
Chris
Chris Latta
Thanks again for the response. Re: the other suggestion, this would work except that I need my both production and development systems to generate reports. I have a solution I'm not happy with which I will post now :)
Chris
A: 

My current answer (which i'm not happy with) is to have 2 VS 2008 projects containing reports. One for development reports and one for production. Each uses a different data source and are deployed into the same SSRS instance under /Reports/Development and /Reports/Production.

Reports are developed/changed in the Dev project and then copied to Production and the data source name changed once ready.

I hate this solution, but it gets around not being able to change the data source on execution via the web service and as a side effect allows me to put the reports, during deployment, into different folders which is not possible from one VS project.

I still don't consider this an answer, 0 points for my bodge! :)

Chris
+1  A: 

Yes try this:

  1. Create two report parameters "Server" and "Database" (you should probably create a default value so the report will run by default)
  2. define the data source as a Expression like so:

    ="data source=" & Parameters!Server.Value & ";initial catalog=" & Parameters!Database.Value

Now you should be able to specify the database and server dynamically at run time

Keep in mind, that the underlying dataset definition needs to be valid in each db and server you execute the report from.

You can also pass the paremeters via a url string like so:

http://server/reportserver?/dir/Report&rs:Command=Render&Server=VALUE1&Database=VALUE2

Keep in mind that these need to be URL encoded and to remember to pass the Value, and not the Label if they are different.

JasonHorner
Thanks Jason, I think this is the answer.
Chris