set connection string at runtime for .trdf

2 posts, 0 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    110 posts
    Member since:
    Nov 2008

    Posted 10 May Link to this post

    Hi,

    I am using asp.net core and we have dev and production environments set up on different machines.

    How can I pass a connection string that is appropriate for the given environment to the .trdf report? I've tried everything I can think of.

    There was a long winded article with what seemed to be a very complicated way of doing something that should be simple.

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

    All I want is to read the appsettings.json file, pull the correct connection string from there and pass it to the .trdf at runtime.

    My kingdom for a simple example!

    Thanks ... Ed

     

  2. Todor
    Admin
    Todor avatar
    321 posts

    Posted 15 May Link to this post

    Hello Ed,

    You should use named (shared) connection string in the report definition (e.g. TRDP file) and register it in the configuration file (e.g. appsettings.json) of the application that will render the reports as explained in the Manual Setup of HTML5 Report Viewer in an ASP.NET Core 2+ application article. Currently the supported format is :

    {
      ...
      "ConnectionStrings": [
        {
          "name": "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString",
          "connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
          "providerName": "System.Data.SqlClient"
        }
      ]
    }


    Starting with the today's' release (R2 2019) we will support two additional formats for registering the shared connections strings in .NET Core :

    "ConnectionStrings": {
      "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString""Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true"
    }

    This type of connection string lacks information about the data provider and will use System.Data.SqlClient as provider invariant name.
    When it will be necessary to specify a different data provider, the following notation will also be supported :

    "ConnectionStrings": {
      "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
        "connectionString""Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
        "providerName""System.Data.SqlClient"
      }
    }


    You may check also our ASP.NET Core demo that comes with the installation of Telerik Reporting - by default it gets deployed in the (Telerik Reporting installation folder)\Examples\CSharp or VB (e.g. C:\Program Files (x86)\Progress\Telerik Reporting R1 2019\Examples\CSharp). The project is CSharp.AspNetCoreDemo - check its appsettings.json.

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top