The requested page is not available for the requested platform. You are viewing the content for Default platform.

Connect the ASP.NET Core Dashboard to an SQL Database

  • 2 min to read

The example below shows how to add the DashboardSqlDataSource to the data source storage and make it available to end users. The dashboard is supplied with data from the SQLite database.

  1. In your application, create the Data folder and add the nwind.db database to it from the following folder:

    C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data

  2. In the Startup.cs file, create a public method that returns a configured in-memory dashboard data source storage (DataSourceInMemoryStorage).

    using DevExpress.DataAccess.Sql;
    public DataSourceInMemoryStorage CreateDataSourceStorage() {
        DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
               DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "sqliteConnection");
                sqlDataSource.DataProcessingMode = DataProcessingMode.Client;
                DevExpress.DataAccess.Sql.SelectQuery query = DevExpress.DataAccess.Sql.SelectQueryFluentBuilder
                    .Build("Sales Person");
                dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml());         
        return dataSourceStorage;
  3. Call the DashboardConfigurator.SetDataSourceStorage method to configure the data source storage. Use the created CreateDataSourceStorage method as the SetDataSourceStorage parameter. Then subscribe to the DashboardConfigurator.ConfigureDataConnection event to pass the connection parameters the SQL data source requires.

    using DevExpress.AspNetCore;
    using DevExpress.DashboardAspNetCore;
    using DevExpress.DashboardWeb;
    public void ConfigureServices(IServiceCollection services) {            
            .AddDefaultDashboardController(configurator => {
                // ...
                configurator.ConfigureDataConnection += Configurator_ConfigureDataConnection;
  4. Provide the required connection parameters at runtime in the DashboardConfigurator.ConfigureDataConnection event handler.

    using DevExpress.DataAccess.ConnectionParameters;
    private void Configurator_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
        if (e.ConnectionName == "sqliteConnection") {
            SQLiteConnectionParameters sqliteParams = new SQLiteConnectionParameters();
            sqliteParams.FileName = "file:Data/nwind.db";
            e.ConnectionParameters = sqliteParams;
  5. As a result, the SQL Data Source is displayed as a Web Dashboard's predefined data source.


    End users can now bind the dashboard items to data in the Web Dashboard's UI. See Binding Dashboard Items to Data in the Web Dashboard's UI for more information.


The example displays how to provide a Web Dashboard with a set of predefined data sources available for end users.