DevExpress-Examples / reporting-asp-net-core-connection-string-configuration

Read connection strings from different configuration sources in an ASP.NET Core application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reporting for ASP.NET Core - Configuration-Dependent Connection Strings for Report Designer

Implementation

In .NET Core applications, the default connection string provider implementation searches the appsettings.json file in the current directory and reads connection strings from the file’s ConnectionStrings section.

This example demonstrates how to get connection strings from a set of different configuration sources in an ASP.NET Core application.

This example implements a custom configuration and loads connection strings from various data sources. This example uses the ConfigurationBuilder class and its AddJsonFile and AddInMemoryCollection extension methods.

Register Connection Strings Globally

To register connection strings from a custom configuration globally, call the static DefaultConnectionStringProvider.AssignConnectionStrings method at the application startup.

These connection strings are available for the Report Designer's Preview to fill a report's data source and generate the resulting document.

In this example, global connection strings are read from the following sources:

  • appsettings.json file;
  • appsettings.Development.json file;
  • in-memory collection.

Register Connection Strings For the Data Source Wizard

The Report Designer obtains connection strings from a custom configuration using the RegisterDataSourceWizardConfigurationConnectionStringsProvider method at the application startup.

The obtained connection strings are shown in the SQL Data Source Wizard in the section that prompts the user to create new data sources. Note that the SQL Data Source Wizard uses only the specified set of connection strings, not including the strings registered globally.

In this example, the Report Designer's connection strings are read from the following files:

  • appsettings.json
  • appsettings.Development.json

Files to Review

Documentation

More Examples

About

Read connection strings from different configuration sources in an ASP.NET Core application.

License:Other


Languages

Language:C# 79.3%Language:HTML 20.6%Language:JavaScript 0.1%