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

Configuration appsettings.json

7 Answers 295 Views
This is a migrated thread and some comments may be shown as answers.
Dev
Top achievements
Rank 1
Dev asked on 31 Jan 2019, 09:07 AM

I'm using Telerik Reporting R1 2019 for ASP.NET Core where the Reporting Services and the HTML5 viewer is at the same project.

Can you direct me to the correct documentation regarding how to set the connection string in this project ?
As I cannot seem to make it work. When it moves to "netcoreapp2.2" does it still need "App.config" to store the connection string ?

I keep getting the unable to connect to database.

7 Answers, 1 is accepted

Sort by
0
Silviya
Telerik team
answered on 04 Feb 2019, 09:49 AM
Hi Dev,

I noticed that you opened a support ticket (#1385458) with same question. Please let me post my answer here as well:

"App configuration in ASP.NET Core uses the new SDK-style project and utilizes appsettings.json as a configuration file. We removed the need of the app.config file. The ConnectionStrings setting should be configured in JSON-based format like for example:
//appsettings.json
"ConnectionStrings": [
    {
      "name": "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString",
      "connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
      "providerName": "System.Data.SqlClient"
    }
  ]

For more information about Telerik Reporting JSON-based configuration structure, please refer to Telerik Reporting Configuration Layout help article.

I need to mention that appsettings.json would be respected if there is an additional configuration included in Startup.cs. In our demos, we provide a new class named ConfigurationService which ensure reading the appsettings.json as config file and used in the ReportsController constructor:
public class ConfigurationService
{
    public IConfiguration Configuration { get; private set; }
     
    public IHostingEnvironment Environment { get; private set; }
    public ConfigurationService(IHostingEnvironment environment)
    {
        this.Environment = environment;
     
        var configFileName = System.IO.Path.Combine(environment.ContentRootPath,"appsettings.json");
        var config = new ConfigurationBuilder()
                        .AddJsonFile(configFileName, true)
                        .Build();
     
        this.Configuration = config;
    }
}

You could refer to the new conceptual documentation article .NET Core Support that explains how to use reports in pure .NET Core application for Windows and Linux platforms.
Additionally, Telerik Reporting ships with a ready-made ASP.NET Core example that demonstrates how to show the sample reports in an ASP.NET Core application. The example also shows how to inject an appsettings.json configuration file to the controller and how to initialize a WebHostBuilder so it runs under Windows and Linux.

The example can be found in the \Examples\CSharp\Asp.NetCoreDemo sub-folder of the Telerik Reporting installation directory."


Regards,
Silviya
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
0
Dev
Top achievements
Rank 1
answered on 12 Feb 2019, 11:20 AM

In that case, can you show me a sample of the appsettings.json for Postgres as a database?

I tried to set like below but the report keep tried to connect to SQL Server.

"ConnectionStrings": [

  {

    "name": "ConnectionName",

    "connectionString": "Server=127.0.0.1;Database=kb;User Id=postgres;Password=postgres",

    "providerName": "Npgsql"

  }

]

 

 

0
Silviya
Telerik team
answered on 14 Feb 2019, 09:49 PM
Hi Dev,

Let me post my answer here as well:
"You are absolutely correct. At this moment, the Telerik Reporting assemblies are built against .NET Standard 2.0 framework. This version has missing support for DbProviderFactories. In general, without DbProviderFactories there's no built-in support for using ADO.NET components without taking a dependency on the data access provider library such System.Data.SqLite, System.Data.Npgsql or System.Data.MySql etc.

The good think is that it would be included in the new .NET Standard 2.1 and it would be supported with Telerik Reporting as well.
Still, we consider this as valid feedback, so I logged it as new feature request on our public Feedback portal on your behalf (Support for DbProviderFactories).

I'm afraid that there is no workaround at the moment."


Regards,
Silviya
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
0
Tim
Top achievements
Rank 1
answered on 05 Feb 2020, 06:20 PM

In a production environment it is common to use appsettings.Production.json and appsettings.Development.json. How do I get the connection string when it is stored in an environment specific config file. We read the config with the following code.

            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var config = new ConfigurationBuilder().AddJsonFile($"appsettings.{env}.json").Build();
            var uiConfig = config.GetSection("UiConfig").Get<UiConfig>();

Thanks.

 

0
Neli
Telerik team
answered on 10 Feb 2020, 10:46 AM

Hi Tim,

To be able to use appsettings.[evn].json, make the following setting in ConfigurationHelper class:

public static IConfiguration ResolveConfiguration(IWebHostEnvironment environment)
{
    string configFileName = null;
    if (environment.IsDevelopment())
    {
        configFileName = "appsettings.Development.json";
    }
    else
    {
        configFileName = "appsettings.Production.json";
    }
    var reportingConfigFileName = System.IO.Path.Combine(environment.ContentRootPath, configFileName);
    return new ConfigurationBuilder()
        .AddJsonFile(reportingConfigFileName, true)
        .Build();
}

The attached project demonstrates the approach.

Regards,
Neli
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
0
Henrique Duarte
Top achievements
Rank 1
Veteran
answered on 01 Apr 2021, 03:43 PM

Any update about it?

I'm trying to use with Oracle.

0
Neli
Telerik team
answered on 06 Apr 2021, 08:25 AM

Hello Henrique,

Have you tested this approach provided in my response? You may be also interested in the suggestion in the How to Retrieve the Oracle Connection Strings from Environment Variables KB article.

Please, let us know if you need further assistance.

Regards,
Neli
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Asked by
Dev
Top achievements
Rank 1
Answers by
Silviya
Telerik team
Dev
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Neli
Telerik team
Henrique Duarte
Top achievements
Rank 1
Veteran
Share this question
or