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

Trying to change connection string at runtime (MVC)

3 Answers 361 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 29 Jul 2014, 08:13 PM
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

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 31 Jul 2014, 07:49 AM
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.

 
0
Roberto
Top achievements
Rank 1
answered on 08 Jan 2015, 07:08 PM
Hello BOB I have the same problem as you, could resolve the error {"message":"Missing report name"}
0
Stef
Telerik team
answered on 12 Jan 2015, 03:22 PM
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.

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