Configuration appsettings.json

4 posts, 0 answers
  1. Dev
    Dev avatar
    9 posts
    Member since:
    Oct 2015

    Posted 31 Jan Link to this post

    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.

  2. Silviya
    Admin
    Silviya avatar
    380 posts

    Posted 04 Feb Link to this post

    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
  3. Dev
    Dev avatar
    9 posts
    Member since:
    Oct 2015

    Posted 12 Feb in reply to Silviya Link to this post

    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"

      }

    ]

     

     

  4. Silviya
    Admin
    Silviya avatar
    380 posts

    Posted 14 Feb Link to this post

    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
Back to Top