There's no way to change the data sources of a report via the ReportViewer. You could change the data source using the web service, but that would actually change the data source on the server for all users - likely not what you want to do.
I think the closest you can get is to build your report with an embedded data source that uses a parameter value to control its connection string. You could build a shared dataset that provides connection strings by name ("Test","Migration",etc) and pass just that name as a parameter to the report.
You would need:
- A shared data source that does not change.
- A shared dataset that returns a list of connection names such as "Test" and "Migration". Let's call that
NamedConnections
. These could come from a table in the shared data source or could be hard-coded in the dataset's query.
- A shared dataset that takes a
@NamedConnection
parameter and returns a single string value that is a complete connection string. Again, these could come from the database or be hard-coded. We'll call it SelectedConnection
- A
@NamedConnection
parameter on the report. This should be visible and should use the NamedConnections
dataset for its available values.
- A
@ConnectionString
internal parameter on the report that uses the SelectedConnection
dataset for its default value.
- An embedded data source in the report that does not use the
@ConnectionString
parameter. This allows you to use the dataset designer to build your dataset(s). I'll call it StaticConnection
.
- An embedded data source in the report that does use the
@ConnectionString
parameter as its connection string. Once the report design is complete and ready to be deployed, switch your dataset(s) to use this data source. Let's call it DynamicConnection
.
Now using the ReportViewer, for instance, you pass the value "Test" to the @NamedConnection
parameter. Then the SelectedConnection
dataset can run and provide the appropriate connection string to the @ConnectionString
parameter which is then used by the DynamicConnection
data source.
The actual data source reference never changes, but the connection string within it does.