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

REST Service Report - Change connection string

2 Answers 181 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 01 Jul 2014, 02:17 AM
Hi,

I've followed the example to create a REST service and a MVC5 view:
http://blogs.telerik.com/telerikreportingteam/posts/14-01-06/consuming-telerik-rest-service-reports-in-asp.net-mvc-5

What we need to do now is work out how we can change the connection string during runtime.

After researching the examples online the suggestions don't seem to be relevant for WebApi.

Please help! 

Thanks.

2 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 01 Jul 2014, 04:15 PM
Hello Michael,

Details about the HTML5 Report Viewer and the Reporting REST Service can be found  this forum thread.

At the end of the linked post I described how to use a custom resolver in cases you need to modify or create a report at run-time. Details how to change connection strings of already existing reports are available in the Changing the connection string dynamically according to runtime data KB article.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Michael
Top achievements
Rank 1
answered on 03 Jul 2014, 11:53 AM
Thank you, and that's perfect. 

Pasting my code here for those interested.

    public class ReportsController : Telerik.Reporting.Services.WebApi.ReportsControllerBase
    {
        protected override Telerik.Reporting.Services.Engine.IReportResolver CreateReportResolver() {
            
            return new CustomReportResolver();

        }

        protected override Telerik.Reporting.Cache.Interfaces.ICache CreateCache()
        {
            return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache();
        }
    }

    class CustomReportResolver : Telerik.Reporting.Services.Engine.IReportResolver
    {
 

        public Telerik.Reporting.ReportSource Resolve(string reportId)
        {
            var rpt = new UriReportSource();
            var reportPath = HttpContext.Current.Server.MapPath("~/Reports");
            rpt.Uri = reportPath + "/" + reportId;

     
            var conn= "Data Source=localhost;Initial Catalog=xxx;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework";
           

            var csMgr = new ReportConnectionStringManager(conn);
            var updatedReport = csMgr.UpdateReportSource(rpt);

            return updatedReport;

        }  See link from Stef on source code for ReportConnectionStringManager








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