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

set connection string at runtime for .trdf

1 Answer 1222 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 10 May 2019, 10:37 AM

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

 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 15 May 2019, 07:13 AM
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
Max
Top achievements
Rank 1
commented on 18 Oct 2021, 07:28 PM

Hi Todor,

Seeing plenty of examples like this all using the same connection string name: Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString".

I'm guessing the name is important here?

Thanks,

Max

Todor
Telerik team
commented on 19 Oct 2021, 03:05 PM

Hi Max,

The name of the Named/Shared ConnectionString can be any valid string value. We use  "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString" for our demo reports, and for that reason our sample code also uses this name. That said, the name is not important. You just need to make sure the name used in the reports is correctly linked to a real connection string in the configuration.

Tags
General Discussions
Asked by
Randy Hompesch
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or