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

Connection Strings in ASP.NET Core App

3 Answers 684 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Arie
Top achievements
Rank 1
Arie asked on 16 Feb 2017, 02:02 PM

Do you have an example of how we should be setting our connection string in an asp.net core app. The docs talk about setting an app.config file in the base directory.

Is this supposed to be in the wwwroot folder and if so what format does it need to take?

Normally in these applications we are putting connection strings in an appsettings.json file and the framework has methods to access these.

Is there something that we can override so that the connection string will be read from here?

I have already checked this http://www.telerik.com/support/kb/reporting/details/changing-the-connection-string-dynamically-according-to-runtime-data

but it seems unwieldy because it looks like you have to actually manually update the report source for the report you are rendering...

I would much prefer that I just pull it from my connectionstrings section in appsettings.config like I do in my Startup.cs like so

Configuration.GetConnectionString("DefaultConnection")

and I believe that Configuration can be passed in via DI using IConfigurationRoot?

 

Thanks
AJ

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 17 Feb 2017, 03:59 PM
Hi AJ,

The Reporting Engine uses a ConfigurationManager to read connection strings, which requires the hack with the app.config in a .NET COre project.
The app.config must be added on the root level of the project (on the level of project.json), not in the wwwroot folder.

The content would as of a standard App.config in XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString"
        connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=SSPI"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>


If you want to set manually connection strings, this involves modifying reports at run-time via custom resolver for the Reporting REST service - example.

Regards,
Stef
Telerik by Progress
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, 09:00 PM

Is this hack appropriate for a 2021 .NET 5 project? I'm really struggling to get any environment other than local to work!
Neli
Telerik team
commented on 19 Oct 2021, 01:17 PM

For .NET Core projects, you need to add the connection string to the appsettings.json file:

 

 

"ConnectionStrings": {
    //This connection string will use System.Data.SqlClient as data provider invariant name.
    //"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=SSPI"

    //This connection string explicitly states the data provider invariant name - mandatory for databases other than MSSQL Server.
    "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
      "connectionString": "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=SSPI",
      "providerName": "System.Data.SqlClient"
    }
  },

You can also check the  .NET5 demo project which can be found in the installation folder of Telerik Reporting:

C:\Program Files (x86)\Progress\Telerik Reporting R3 2021\Examples\CSharp\.NET 5\

0
Arie
Top achievements
Rank 1
answered on 21 Feb 2017, 03:36 PM

I have added the app.config file ....added the same connection string that I use for my EF stuff in appsettings.json ...changed the name to match what I named the connection in my report ... and still get the same error...

 

Is there some kind of naming convention that I should use or some way to set up my datasource connection that is key to getting this to work?

 

AJ

0
Stef
Telerik team
answered on 21 Feb 2017, 05:04 PM
Hi AJ,

Please test to restart IIS express and then run the application. It is possible that you see an old cached version.

If this doe snot resolve the issue, please open a support ticket and send us a demo project that illustrates the settings.

Regards,
Stef
Telerik by Progress
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
Tags
General Discussions
Asked by
Arie
Top achievements
Rank 1
Answers by
Stef
Telerik team
Arie
Top achievements
Rank 1
Share this question
or