Handling Multi-User Database Connections in Telerik Reporting
Environment
Version | Product | Author |
---|---|---|
18.2.24.806 | TelerikReporting | Desislava Yordanova |
Description
When developing an application with Telerik Reporting that involves multiple users connecting to different databases, it becomes essential to dynamically set the connection strings based on the user. This KB article also answers the following questions:
- How can I set connection strings dynamically for each user in Telerik Reporting?
- What is the best practice for handling multiple database connections in a multi-user environment with Telerik Reporting?
- How to implement custom connection string settings in the Telerik Web Report Designer?
Solution
To handle multiple users connecting to different databases in Telerik Reporting, follow the steps below:
-
Store Common Connections: For connections that should be available to all users, store them in the
appsettings.json
file. Telerik Reporting resolves connection strings using the alias(name) of the connection by reading from the configuration file loaded by the application. -
Implement Custom ISettingsStorage: For user-specific connections, implement a custom version of the ISettingsStorage interface. Override the GetConnections() method to dynamically set the connection string based on the current user. Create a list of
ConnectionInfo
objects where theName
remains the same, and only theConnectionString
is set dynamically.A sample implementation can be found in the article Implementing Encrypted Connection Strings with Telerik Reporting. Although it focuses on decrypting connection strings, it provides a clear example of how to dynamically adjust connection strings.
Adjust Connection String at Preview: When a report is previewed in the Web Report Designer, use the ReportSourceResolver property of the ReportServiceConfiguration object to set up a custom IReportSourceResolver where you can dynamically change the connection string. The process for changing connection strings during report preview is detailed in Decrypting Connection Strings for SqlDataSource Components - HTML5 Report Viewers.
By following these steps, you can efficiently manage multiple users connecting to different databases in your Telerik Reporting application.