Back to Devexpress

Use SQL Data Sources (ASP.NET Core Blazor)

expressappframework-404405-analytics-dashboards-use-sql-data-sources-asp-net-core-blazor.md

latest2.3 KB
Original Source

Use SQL Data Sources (ASP.NET Core Blazor)

  • Jul 09, 2025
  • 2 minutes to read

This topic explains how use an SQL data source with Dashboards. The data source content is based on the application’s Business Model.

Enable SQL Data Sources

To enable SQL data sources in your application, supply the dashboard configurator with a connection strings provider in the MySolution.Blazor.Server\Startup.cs file. Review the following code sample:

csharp
// ...
using DevExpress.DashboardAspNetCore;
// ...
public class Startup {
   // ...
    public void ConfigureServices(IServiceCollection services) {
        // ...
        services.AddXaf(Configuration, builder => {
            builder.UseApplication<MySolutionBlazorApplication>();
            builder.Modules
                // ...
                .AddDashboards(options => {
                    options.DashboardDataType = typeof(DashboardData);
                    options.SetupDashboardConfigurator = (dashboardConfigurator, serviceProvider) => {
                        dashboardConfigurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration));
                    };
                });
            // ...
        });
        // ...
    }
}

Use the DashboardConnectionStringsProvider class to create new SQL data sources based on connection strings from the MySolution.Blazor.Server\appsettings.json file.

Allow Custom SQL Queries

To enable custom SQL queries in your application, follow the steps below:

  1. In the MySolution.Blazor.Server\Startup.cs file, enable custom SQL queries on the server side:

  2. In the MySolution.Blazor.Server project, create a custom Razor component named DashboardSettingsHelper with the following definition:

  3. In the MySolution.Blazor.Server\Controllers folder, create the following Controller:

End-users can now write custom SQL queries.