I want end-users to design their own reports to run in an application where the database connection is dynamic. This was sort-of covered in a previous post but now that I understand things better I wanted to ask the right questions. The options I have got are:
1. Use sql connector in the designer with a 'shared' connection string (where the alias is the same name as stored in web.config). This works great as the user can do their own joins using the query builder, slap the reports into the website and they work. BUT there is no connection string in my web.config, it is stored elsewhere.
2. Extend the standalone designer so the users can use an Object Datasource to use my custom dll BUT then all the joins need to be pre-defined in the dll code. (I have already got this working, but joining all the tables is a real problem + confusing for the uesr)
So what I want to ask - is there any way I can use case 1 by switching the connection string at run time (I have all the info available in memory, it's just not static in web.config)?
12 Answers, 1 is accepted
By default, SqlDataSource components read their connection strings from the application's configuration file via ConfigurationManager.
If you want to make changes, you can get a Telerik.Reporting.Report instance and update all DataSource properties of data items in it. Please consider the example in Changing the connection string dynamically according to runtime data.
In the case of the HTML5 Viewer and Reporting REST service, such code can be executed in a custom resolver for the Reporting REST service. An example is available in this forum post.
Let us know if you have further questions.
That sounds like it's just what I need. Quite a lot to digest though, I'll report back once I've run some tests.
Ok, It seems I have this working after combining/reworking some of the concepts at the links provided by Stef.
- ReportConnectionStringManager class comes from here as-is
- The standard reports controller now uses a custom resolver instead of the default one
- The custom resolver returns a report instance with the db connection switched
@Stef: please confirm that my approach is correct and all aspects of the db connection will be updated (ie. all report items/parameters etc.)
In general, the code snippet illustrates the suggested approach. The issue you may have are:
- Where you are deserializing a report by using a UriReportSource.Uri, make sure that the path is routed correctly as it is done for the first UriReportSource;
- If reports use NavigateToReportAction, the NavigateToReportAction.ReportSource property will be using an instance of a report. This is not supported for actions and the navigation will not be available in the HTML5 Viewer.
You can replace the NavigateToReportAction with a NavigatetoUrlAction, where the URL can point to the same page but with different query string. The information from the query string can be used to update the viewer on the page.
TRDP files are introduced in R2 2016. They can be handled in a similar way as TRDX files - Report Packaging. Thus the code from Changing the connection string dynamically according to runtime data should be extended to cover TRDP files recognition and unpackaging.
Can you pls explain what you mean by "should be extended to cover TRDP files recognition and unpackaging."? I don't see any reference to trdp or trdx in the ReportConnectionStringManager class.
Please check the UpdateReportSource method and the case handling UriReportSource. In this method you need to check the Uri for the file's extension - TRDX or TRDP, and to provide proper handling (deserializing or unpackaging). There are two methods for deserializing TRDX files or XML - DeserializeReport, but you will need to add your own for unpackaging.
Telerik by Progress
Quick question, I use UriReportSource for both tdrp and tdrx, it seems to work fine but is this correct?
ie. I am only editing the DeserializeReport(UriReportSource uriReportSource) overload to cater for tdrx and tdrp
It is possible to include unpackaging in the DeserializeReport method.
Telerik by Progress
Ok thanks. Here is the code I have working in my custom resolver to resolve trdp + trdx, if anyone needs it: