Change programmaticaly the connection string of the report

edited August 2013 in FastReport .NET
Hello
I use the FR .Net with Razor (2013.3).

I'd like to change the connection string programmaticaly but I don't find how.

I tryied the 2 first code in http://www.fast-report.com/public_download...erManual-en.pdf in the "Passing own connection string" chapter.

1) report1.Dictionary.Connections[0].ConnectionString = my_connection_string;

2) the second with the parameter

These 2 code didn't work, and I don't know why.

And finally the third, I didn't found how to change the "EnvironmentSettings component"

Can you help me ?

Regards

Comments

  • edited 3:12PM
    string report_path = Server.MapPath("~//Content//Reports//test.frx");
    webReport.Width = 1000; // set width
    webReport.Height = 1200; // set height
    webReport.LocalizationFile = Server.MapPath("~//Content//Reports//Localizations//Persian.frl");
    webReport.DesignerLocale = "fa";

    webReport.Report.Load(report_path);
    webReport.Report.Dictionary.Connections[0].ConnectionString = domain.ConnectionString;
    return View(webReport);


    you most first "webReport.Report.Load(report_path);" then change "webReport.Report.Dictionary.Connections[0].ConnectionString = YOUR_CONNECTION_STRING;"
  • Hello!

    Direct replacement of the connection string (Connections[0].ConnectionString): Set the connection string immediately after webReport.Report.Load(...):

    var webReport = new WebReport();
    webReport.Report.Load(reportPath);
    
    if (webReport.Report.Dictionary.Connections.Count > 0)
    {
    webReport.Report.Dictionary.Connections[0].ConnectionString = myConnectionString;
    }
    
    return View(webReport);
    

    Global handler instead of the EnvironmentSettings component:

    FastReport.Utils.Config.ReportSettings.DatabaseLogin += (sender, e) =>
    {
    e.ConnectionString = myConnectionString;
    };
    
This discussion has been closed.