Back to Devexpress

Register SQL Data Connections

xtrareports-400279-web-reporting-asp-net-core-reporting-end-user-report-designer-in-asp-net-applications-use-data-sources-and-connections-sql-database-register-connections.md

latest12.9 KB
Original Source

Register SQL Data Connections

  • Nov 07, 2025
  • 7 minutes to read

This document describes how to create a set of SQL data connections for the End-User Report Designer in ASP.NET Core Applications. The Data Source Wizard displays these connections when users create new SQL data sources.

Tip

Online Example : How to read connection strings from different configuration sources in an ASP.NET Core application

Requirements

The SQL Data Source Wizard can use only connection strings that contain the XpoProvider key. Otherwise, the “Schema loading failed.” error occurs.

You can use one of the following approaches to avoid this error:

Use the Default Connection String Provider

Use this approach to provide the Report Designer with connection strings registered in an application globally.

Register the Default Implementation

In ASP.NET Core applications, the default connection string provider implementation uses the IConfiguration service to read connection strings. Applications created based on ASP.NET Core templates call the CreateDefaultBuilder method in the Program.cs file to register this service. If the IConfiguration service is not registered, the default provider searches the appsettings.json file in the current directory and reads connection strings from the file’s ConnectionStrings section.

To enable the Report Designer to use this provider, call the static ReportDesignerConfigurationBuilder.RegisterDataSourceWizardConfigFileConnectionStringsProvider method at application startup.

csharp
using Microsoft.Extensions.DependencyInjection;
using DevExpress.AspNetCore;
using DevExpress.AspNetCore.Reporting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDevExpressControls();
builder.Services.ConfigureReportingServices(configurator => {
    configurator.ConfigureReportDesigner(designerConfigurator => {
        designerConfigurator.RegisterDataSourceWizardConfigFileConnectionStringsProvider();
    });
});

var app = builder.Build();

Override the Default Implementation

You can override the default connection string provider to get connection strings from appsettings.Development.json , connectionStrings.json , in-memory collection, and other 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.

  2. Call the static DefaultConnectionStringProvider.AssignConnectionStrings method at application startup after the UseDevExpressControls method to register connection strings globally.

  3. Call the static ReportDesignerConfigurationBuilder.RegisterDataSourceWizardConfigFileConnectionStringsProvider method at application startup as shown above.

Important

When the SQL Data Source Wizard obtains connection strings from configuration sources, only the connection names are serialized with the report definition.

Build a Custom Configuration for the Designer Only

This approach allows you to provide the Report Designer with an individual set of connection strings. You can also make the Designer read these strings from multiple configuration sources.

  1. Create the ConfigurationBuilder class instance and use its extension methods (AddJson, AddInMemoryCollection, etc.) to add configuration sources. See Configuration in ASP.NET Core for more information.

  2. Call the ReportDesignerConfigurationBuilder.RegisterDataSourceWizardConfigurationConnectionStringsProvider method at the application’s startup after the AddDevExpressControls method call.

Note that if you registered connection strings at the Designer level, the SQL Data Source Wizard does not use the strings registered globally. The latter strings are available for the Report Designer’s Preview to fill a report’s data source and generate the resulting document.

Implement a Custom Connection String Provider

Use this approach to implement complex logic for specifying connection strings.

To configure connection strings based on strings from the appsettings.json file, follow the steps below.

  1. Implement the IDataSourceWizardConnectionStringsProvider interface as demonstrated below to create a custom connection string provider.

  2. Call the static ReportDesignerConfigurationBuilder.RegisterDataSourceWizardConnectionStringsProvider<T> method at application startup to register the custom connection string provider.

Implement a Custom Connection String Service

If your application architecture requires the usage of dependency injection inside the IDataSourceWizardConnectionStringsProvider service, the only solution is to call the RegisterDataSourceWizardConnectionStringsProvider method without passing the overrideWebConfigConnections parameter. In this situation, data connection settings are saved alongside the report layout.

Security reasons mean you should not save connection parameters in the report layout. To ensure security, register the IConnectionProviderFactory service. The purpose of that service is creating an instance of the IConnectionProviderService that supplies connection data to Web Reporting components. Move the connection loading logic from the IDataSourceWizardConnectionStringsProvider to the IConnectionProviderService.

The following code example uses dependency injection to pass the IHostingEnvironment service to code that loads connections:

csharp
public class MyDataSourceWizardConnectionStringsProvider : IDataSourceWizardConnectionStringsProvider {
    private readonly IHostingEnvironment hosting;

    public MyDataSourceWizardConnectionStringsProvider(IHostingEnvironment hosting) {
        this.hosting = hosting;
    }

    public Dictionary<string, string> GetConnectionDescriptions() {
        // Load list of connections here
        // ...
    }

    public DataConnectionParametersBase GetDataConnectionParameters(string name) {
        // Move implementation logic to the IConnectionProviderService.LoadConnection method
        return null;
    }
}

// Only this class gets IHttpContextAccessor injected
public class MyConnectionProviderFactory : IConnectionProviderFactory {
    private readonly string username;

    public MyConnectionProviderFactory(IHttpContextAccessor httpContextAccessor) {
        var httpContext = httpContextAccessor.HttpContext;
        if (httpContext?.User?.Identity?.IsAuthenticated == true) {
            username = httpContext.User.Claims.FirstOrDefault(c => c.Type == "username")?.Value;
        }
    }

    public IConnectionProviderService Create() {
        return new MyConnectionProviderService(username);
    }
}

// This class receives only plain data (no injected services)
public class MyConnectionProviderService : IConnectionProviderService {
    private readonly string username;

    public MyConnectionProviderService(string username) {
        this.username = username;
    }

    public SqlDataConnection LoadConnection(string connectionName) {
        // Use the stored username here as needed
        // e.g., load user-specific connection settings
        var connectionParameters = new CustomConnectionParameters(MyDataLayer.GetConnectionString(username, connectionName));
        return new SqlDataConnection(connectionName, connectionParameters);
    }
}

Register services at application startup:

csharp
builder.Services.ConfigureReportingServices(configurator => {
    configurator.ConfigureReportDesigner(designerConfigurator => {
        designerConfigurator.RegisterDataSourceWizardConnectionStringsProvider<MyDataSourceWizardConnectionStringsProvider>();
    });
    configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
        viewerConfigurator.RegisterConnectionProviderFactory<MyConnectionProviderFactory>();
        // ...
    });
});

For more information, review the following help topic: SQL Database - Update Connections in the End-User Report Designer (ASP.NET Core).

The IDataSourceWizardConnectionStringsProvider interface allows you to fill the connection string list for the SQL Data Source Wizard only.

If you print or export reports in code outside the End-User Report Designer’s context, implement the cross-platform IConnectionProviderService interface instead. This interface allows you to restore the data connections specified in the report and its child detail report bands.

See Also

SQL Database - Customize the Schema

Register Predefined Data Sources (ASP.NET Core)

Register JSON Data Connections (ASP.NET Core)

Bind Reports to Data - SQL Database