dashboard-116652-web-dashboard-integrate-dashboard-component-dashboard-backend-prepare-data-source-storage-for-the-aspnet-core-framework-sql-data-source.md
This topic shows how to add the DashboardSqlDataSource to an in-memory data source storage, and make it available to users.
To configure an SQL data source, specify a database connection first and then create the data source in code or in the UI.
You can specify a connection to the database in one of the following ways:
Specify a connection in appsettings.json. Use this way when creating a data source both in the UI and in code.
Implement a custom connection string provider. A custom data connection provider allows you to add custom logic. For example, you can read connection strings from a custom source or manage connection strings between users. To use a custom connection provider, implement the IDataSourceWizardConnectionStringsProvider interface and pass the new provider to the DashboardConfigurator.SetConnectionStringsProvider method call. See the following topic for details: Register Default Data Connections.
Handle the DashboardConfigurator.ConfigureDataConnection event to specify the connection parameters at runtime and assign them to the e.ConnectionParameters property. Use this event to create a data source in code.
To create a new SQL Data Source, follow the steps below:
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Sql;
DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString");
sqlDataSource.DataProcessingMode = DataProcessingMode.Client;
SelectQuery query = SelectQueryFluentBuilder
.AddTable("Categories")
.Join("Products", "CategoryID")
.SelectAllColumnsFromTable()
.Build("Products_Categories");
sqlDataSource.Queries.Add(query);
Call the DataSourceInMemoryStorage.RegisterDataSource method to register the data source in the data source storage. Call the DashboardConfigurator.SetDataSourceStorage method to specify the data source storage for the Web Dashboard.
// Create a data source storage.
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
// Register the SQL data source.
dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml());
// Register the storage for the Web Dashboard.
configurator.SetDataSourceStorage(dataSourceStorage);
The SQL Data Source is now available in the Web Dashboard:
Users can bind dashboard items to data in the Web Dashboard’s UI.
Users can use the Dashboard Data Source Wizard to create a new SQL data source based on an existing connection.
They can create/edit a query, select a stored procedure, or add query parameters.
See the following topic for details: Specify Data Source Settings (Database).
The example shows how to make a set of data sources available for users in the Web Dashboard application.
View Example: How to Register Data Sources for ASP.NET Core Dashboard Control