Change connection string based on user

3 posts, 1 answers
  1. Kyle Smith
    Kyle Smith avatar
    46 posts
    Member since:
    Feb 2012

    Posted 20 Jun 2018 Link to this post

    Is it possible to change a report connection string based on user? We have several instances of a web application (each with their own database). We have multiple reports for this web application and would like to not have to deploy a new set to the report server for each instance. Instead, it would be nice if we could have the report select a connection string based on the user accessing the Telerik Report Server. Is this possible?

    We previously had reports deployed with the standalone Telerik Report Viewer, and the reports used the connection string based on the web.config of the site. However, we changed to using Telerik Report Server to obtain the report subscription and data alerts features.

  2. Answer
    Todor
    Admin
    Todor avatar
    397 posts

    Posted 25 Jun 2018 Link to this post

    Hi Kyle,

    The requirement can be achieved relatively easy for reports without parameters fetching their AvailableValues from an SqlDataSource, which connection string should be modified dynamically.

    In the Report or other Data item (Table, List, etc.) where the connection string is supposed to be changed dynamically introduce a new Binding.
    The Binding can use the exposed UserIdentity properties to set the connection string based on the user. For example:
    Property path                   |   Expression
     
    DataSource.ConnectionString     |   = IIF(UserIdentity.Name = "user1", "user1_ConnectionString",
                        |       IIF(UserIdentity.Name = "user2", "user2_ConnectionString",
                        |       IIF(UserIdentity.Name = "user3", "user3_ConnectionString",AND SO ON...)))

    Note that DataSource.ConnectionString property is not listed in the dropdown and must be typed manually.

    The proposed approach cannot be used to modify the Connection String of Report Parameter -> AvailableValues -> DataSource as report parameters do not expose Bindings. 

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Kyle Smith
    Kyle Smith avatar
    46 posts
    Member since:
    Feb 2012

    Posted 25 Jun 2018 Link to this post

    Thank you! I'll give this a shot--sounds like it does exactly what I want.
Back to Top