This document describes how to provide a Web Dashboard with a set of predefined data connections. These connections are displayed for end-users in the Dashboard Data Source Wizard when creating new data sources.
You can add a predefined connection in the following ways:
Add a connection string specifying a valid connection to the required database to the project's appsetings.json file as shown below. Note that the connection string should contain the XpoProvider parameter that corresponds to the database type.
{
"ConnectionStrings": {
"MS SQL Connection": "XpoProvider=MSSqlServer; data source=localhost; initial catalog=Northwind; Integrated Security=SSPI; Persist Security Info=True;",
"XML Connection": "XpoProvider=InMemoryDataStore;Read Only=true;Data Source=Data\\nwind.xml;"
}
}
After defining connection strings, create the DashboardConnectionStringsProvider instance and pass it to the DashboardConfigurator.SetConnectionStringsProvider method.
using DevExpress.DashboardWeb;
// ...
public void ConfigureServices(IServiceCollection services) {
services
// ...
.AddDefaultDashboardController(configurator => {
configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration));
});
// ...
}
To learn how to specify the XpoProvider parameter, see How to Specify a Custom Connection String for the SQL Data Source.
Specify a data connection provider using the DashboardConfigurator.SetConnectionStringsProvider method.
This example shows how to implement a custom connection strings provider by implementing the IDataSourceWizardConnectionStringsProvider interface:
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Native;
using DevExpress.DataAccess.Web;
// ...
public class MyDataSourceWizardConnectionStringsProvider : IDataSourceWizardConnectionStringsProvider {
public Dictionary<string, string> GetConnectionDescriptions() {
Dictionary<string, string> connections = new Dictionary<string, string>();
// Customize the loaded connections list.
connections.Remove("LocalSqlServer");
connections.Add("msSqlConnection", "MS SQL Connection");
connections.Add("xmlConnection", "XML Connection");
return connections;
}
public DataConnectionParametersBase GetDataConnectionParameters(string name) {
// Return custom connection parameters for the custom connection.
if (name == "msSqlConnection") {
return new MsSqlConnectionParameters("localhost", "Northwind", "", "", MsSqlAuthorizationType.Windows);
} else if (name == "xmlConnection") {
return new XmlFileConnectionParameters("C:\\Users\\Public\\Documents\\DevExpress Demos 18.2\\Components\\Data\\nwind.xml");
}
return AppConfigHelper.LoadConnectionParameters(name);
}
}
After implementing a custom connection strings provider, pass this class's instance to the DashboardConfigurator.SetConnectionStringsProvider method:
using DevExpress.DashboardWeb;
// ...
public void ConfigureServices(IServiceCollection services) {
services
// ...
.AddDefaultDashboardController(configurator => {
configurator.SetConnectionStringsProvider(new MyDataSourceWizardConnectionStringsProvider());
});
// ...
}