This is a migrated thread and some comments may be shown as answers.

Dynamically change connection string of a parameter

1 Answer 251 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 31 Mar 2015, 08:32 PM
I'm using the Standalone report viewer as I'm not a developer, though I can muddle through some stuff. I am writing a report where 95% of the data is in a customer database. 

There is a database that contains the database name of the available customer databases. At run time, the user would select the customer to run the report for, and the report would retrieve the database name from this master database.

I then have two other parameters that the user would need to select based on values in the customer database for the selected customer. I want to generate a list of available values, but to do so, I need to use the first parameter to retrieve the database name, then change the connection string of the second parameter. Once the user selects these values, I can then pass them to the subreports that make up the reports and use them to update the connection strings.

I  have written a custom library using the examples found here so I can change the connection string and it works for the sub reports.

However, I'm trying to figure out a way to do the same for the parameters.  I tried putting my custom function call into the ConnectionString parameter in place of the defined connection that is selected in the Report Viewer but that didnt seem to work, or I didn't do it correctly.

Is there a way to do what I need to here?

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 02 Apr 2015, 01:59 PM
Hello Tracy,

The SqlDataSource.ConnectionString property does no support expressions. Thus, it is not possible to use a report parameter value to set the connection string of another data source component.

Changing the connection string can be achieved programmatically. One of the possible approaches is described in detail in the Changing the connection string dynamically according to runtime data KB article:
foreach (var parameter in report.ReportParameters)
{
    if (parameter.AvailableValues.DataSource is SqlDataSource)
    {
        var sqlDataSource = (SqlDataSource)parameter.AvailableValues.DataSource;
        sqlDataSource.ConnectionString = connectionString;
    }
}


Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
General Discussions
Asked by
Tracy
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or