Dynamically change connection string of a parameter

2 posts, 0 answers
  1. Tracy
    Tracy avatar
    13 posts
    Member since:
    Nov 2010

    Posted 31 Mar 2015 Link to this post

    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?

  2. Nasko
    Admin
    Nasko avatar
    1045 posts

    Posted 02 Apr 2015 Link to this post

    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.

     
Back to Top