Skip to main content

ReportDesignerConfigurationBuilder.RegisterDataSourceWizardConfigurationConnectionStringsProvider(IConfigurationSection) Method

Registers connection strings to display in the Data Source Wizard based on a custom configuration.

Namespace: DevExpress.AspNetCore.Reporting

Assembly: DevExpress.AspNetCore.Reporting.v23.2.dll

NuGet Package: DevExpress.AspNetCore.Reporting

Declaration

public ReportDesignerConfigurationBuilder RegisterDataSourceWizardConfigurationConnectionStringsProvider(
    IConfigurationSection connectionStringsSection
)

Parameters

Name Type Description
connectionStringsSection IConfigurationSection

A section of application configuration values.

Returns

Type Description
ReportDesignerConfigurationBuilder

A ReportDesignerConfigurationBuilder that can be used to further configure the Report Designer services.

Remarks

To enable end-users to create new data sources in the Web Report Designer, you should register connection strings explicitly. The Data Source Wizard displays these connections.

Use the RegisterDataSourceWizardConfigurationConnectionStringsProvider method to provide the Report Designer with connection strings from a set of different configuration sources:

  1. Create a custom configuration and load connection strings from all the required sources. For instance, create the ConfigurationBuilder class instance and use its extension methods (AddJson, AddInMemoryCollection, etc.) See Configuration in ASP.NET Core for more information.

    using System.Collections.Generic;
    using Microsoft.Extensions.Configuration;
    
    public IConfigurationSection GetConnectionStrings() {
      var connectionStrings = new Dictionary<string, string> {
        [$"ConnectionStrings:VehiclesInMemory"] = "XpoProvider=SQLite;Data Source=Data/vehicles.db",
        [$"ConnectionStrings:CarsInMemory"] = "XpoProvider=SQLite;Data Source=Data/cars.db;"
      };
      return new ConfigurationBuilder()
        .SetBasePath(hostingEnvironment.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{hostingEnvironment.EnvironmentName}.json", optional: true)
        .AddInMemoryCollection(connectionStrings)
        .Build()
        .GetSection("ConnectionStrings");
    }
    
  2. Call the RegisterDataSourceWizardConfigurationConnectionStringsProvider method at application startup after the AddDevExpressControls method call.

    using DevExpress.AspNetCore;
    using DevExpress.AspNetCore.Reporting;
    using Microsoft.Extensions.DependencyInjection;
    
    var builder = WebApplication.CreateBuilder(args);
    
    builder.Services.AddDevExpressControls();
    builder.Services.ConfigureReportingServices((configurator) => {
        configurator.ConfigureReportDesigner(designer => {
            designer.RegisterDataSourceWizardConfigurationConnectionStringsProvider(GetConnectionStrings());
        });
    });
    
    var app = builder.Build();
    

You can also use the static DefaultConnectionStringProvider.AssignConnectionStrings method to register specific connection strings globally. These connection strings are available for the Report Designer’s Preview to fill a report’s data source and generate the resulting document. The SQL Data Source Wizard does not use these global strings if you registered strings at the Report Designer level.

View Example: Report Designer - How to read connection strings from different configuration sources in an ASP.NET Core application

See SQL Database - Register Connections for more information.

See Also