Trying to change connection string at runtime (MVC)

4 posts, 0 answers
  1. Bob
    Bob avatar
    10 posts
    Member since:
    Jul 2010

    Posted 29 Jul 2014 Link to this post

    I am trying to change the connection string of a UriReportSource at runtime in an MVC 4 application.  I am using this page as a guide:

    http://www.telerik.com/support/kb/reporting/details/changing-the-connection-string-dynamically-according-to-runtime-data

    However I end up getting this error: "Unable to get report parameters: Missing report name"

    Here is the ReportsController:

    public class ReportsController : ReportsControllerBase
    {
        protected override IReportResolver CreateReportResolver()
        {
     
            var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");
     
            return new ReportFileResolver(reportsPath)
                .AddFallbackResolver(new ReportTypeResolver());
            //return new CustomReportResolver();
        }
     
        protected override ICache CreateCache()
        {
            return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache();
        }
    }

    Code for the controller for the view containing the ReportViewer:

    public ActionResult Index()
    {
        string connectionString = GetConnectionString();
        ReportConnectionStringManager connStringManager = new ReportConnectionStringManager(connectionString);
        string uri = Server.MapPath("/Reports/Tickets2.trdx");
        UriReportSource theReport = new UriReportSource() { Uri = uri };
        InstanceReportSource fixedReport = connStringManager.UpdateReportSource(theReport);
        return View(new ReportModel() { TheReport = fixedReport });
    }
     (Note that ReportModel.TheReport is of type InstanceReport)

    And the View:

    @model FastTrack.MVC.Models.ReportModel
    @{
        ViewBag.Title = "Reports";
    }
     
    @section styles
    {      
        <link href="ReportViewer/styles/telerikReportViewer-8.1.14.618.css" rel="stylesheet" />
    <style>
            #reportViewer1 {
                position: relative;
                width: 100%;
                height: 1000px;
                font-family: 'segoe ui', 'ms sans serif';
                overflow: hidden;
            }
        </style>
        <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
    }
     
    @section scripts
    {
        <script src="ReportViewer/js/telerikReportViewer-8.1.14.618.js"></script>
    }
    <div class="container">
    <div class="row">
                @(Html.TelerikReporting().ReportViewer()
                       .Id("reportViewer1")
                       .ServiceUrl("/api/reports/")
                       .TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate-8.1.14.618.html")
                       .ReportSource(@Model.TheReport)
                       .ViewMode(ViewModes.INTERACTIVE)
                       .ScaleMode(ScaleModes.SPECIFIC)
                       .Scale(1.0)
                       .PersistSession(false)
                       )
     
        </div>
        </div>

    I have verified that passing the reportviewer is working when simply passing the report in as a Uri, but we have to be able to change the connection string dynamically because or data/connections are tenant-based.

    Any help is appreciated
  2. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 31 Jul 2014 Link to this post

    Hello Bob,

    The HTML5 viewer is a client-side widget served through a running Reporting REST service. This technology allows the integration of the viewer in any web project, not only MVC.

    For more details about how it works and the required settings, please check this forum thread.
    In the thread is mentioned also the approach with using a custom report resolver to modify the report before processing it.

    I hope the above information helps you.

    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.

     
  3. Roberto
    Roberto avatar
    2 posts
    Member since:
    Feb 2013

    Posted 08 Jan 2015 in reply to Bob Link to this post

    Hello BOB I have the same problem as you, could resolve the error {"message":"Missing report name"}
  4. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 12 Jan 2015 Link to this post

    Hello Roberto,

    Please check my post in the Changing a parameter's datasource connection string at runtime forum thread. If you need further help, let us continue the discussion in the above linked thread to avoid splitting the details.

    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.

     
Back to Top