Back to Devexpress

Register Data Connections for Web Dashboard

dashboard-119823-web-dashboard-integrate-dashboard-component-dashboard-backend-register-default-data-connections.md

latest9.0 KB
Original Source

Register Data Connections for Web Dashboard

  • Jan 05, 2026
  • 4 minutes to read

Register data connections to allow users to create data sources in the Dashboard Data Source Wizard. To create a data connection, add a connection string to the configuration file or implement a custom data connection provider.

Add a Connection String to the Configuration File

For security reasons, specify connection strings in the application’s configuration file (appsettings.json for ASP.NET Core and Web.config for ASP.NET MVC).

ASP.NET Core

json
{
    "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;",
        "JSON Connection to URI": "uri=https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json",
        "MongoDB (local)": "mongodb://localhost:27017/"
    }
}

ASP.NET MVC

xml
<configuration>
    <connectionStrings>
        <add name="MsSqlConnection" connectionString="XpoProvider=MSSqlServer; data source=localhost; initial catalog=Northwind; integrated security=SSPI;" />
        <add name="XmlConnection" connectionString="XpoProvider=InMemoryDataStore;Read Only=true;Data Source=Data\\nwind.xml;" />
        <add name="JsonConnection" connectionString="uri=https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json" />
        <add name="MongoDB (local)" connectionString="mongodb://localhost:27017/" />
    </connectionStrings>
</configuration>

The Web Dashboard control does not expose connection string names to the client. If a user creates a data source in the Data Source Wizard, the control throws an exception when it attempts to load connection strings. To resolve this behavior, call the DashboardConfigurator.SetConnectionStringsProvider method and pass the predefined connection strings provider instance.

Use the following providers based on the platform:

The following code snippets use the default provider:

ASP.NET Core

csharp
using DevExpress.DashboardWeb;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDevExpressControls();
builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
    DashboardConfigurator configurator = new DashboardConfigurator();
    // ...
    configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration));

    return configurator;
});

var app = builder.Build();

ASP.NET MVC

csharp
DashboardConfigurator.Default.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider());
vb
DashboardConfigurator.Default.SetConnectionStringsProvider(New DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider())

Create a Custom Data Connection Strings Provider

Use the DashboardConfigurator.SetConnectionStringsProvider method to specify a data connection provider.

A custom data connection strings provider allows you to inject application-specific logic. Implement the IDataSourceWizardConnectionStringsProvider interface and pass the provider instance to the SetConnectionStringsProvider method.

The following example implements a custom connection strings provider.

csharp
using DevExpress.DataAccess.ConnectionParameters;
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.Add("jsonUrlConnection", "JSON URL Connection");
        connections.Add("msSqlConnection", "MS SQL Connection");
        return connections;
    }

    public DataConnectionParametersBase GetDataConnectionParameters(string name) {
        // Return custom connection parameters for the custom connection.
        if (name == "jsonUrlConnection") {
            return new JsonSourceConnectionParameters() { 
                JsonSource = new UriJsonSource(
                    new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json")) 
                };
        } else if (name == "msSqlConnection") { 
            return new MsSqlConnectionParameters("localhost", "Northwind", "", "", MsSqlAuthorizationType.Windows);
        } 
        throw new System.Exception("The connection string is undefined.");
    }
}
vb
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.Web

' ...

Public Class MyDataSourceWizardConnectionStringsProvider
    Implements IDataSourceWizardConnectionStringsProvider
    Public Function GetConnectionDescriptions() As Dictionary(Of String, String)
        Dim connections As New Dictionary(Of String, String)()

        ' Customize the loaded connections list.  
        connections.Add("jsonUrlConnection", "JSON URL Connection")
        connections.Add("msSqlConnection", "MS SQL Connection")
        Return connections
    End Function

    Public Function GetDataConnectionParameters(ByVal name As String) As DataConnectionParametersBase
        ' Return custom connection parameters for the custom connection.
        If name = "jsonUrlConnection" Then
            Return New JsonSourceConnectionParameters() With {.JsonSource = New UriJsonSource(New Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"))}
        ElseIf name = "msSqlConnection" Then
            Return New MsSqlConnectionParameters("localhost", "Northwind", "", "", MsSqlAuthorizationType.Windows)
        End If
        Throw New System.Exception("The connection string is undefined.")
    End Function
End Class

After you implement a custom connection strings provider, create its instance and pass it to the DashboardConfigurator.SetConnectionStringsProvider method:

ASP.NET Core

csharp
using DevExpress.DashboardWeb;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDevExpressControls();
builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
    DashboardConfigurator configurator = new DashboardConfigurator();
    configurator.SetConnectionStringsProvider(new MyDataSourceWizardConnectionStringsProvider());
    // ...
    return configurator;
});

var app = builder.Build();

ASP.NET MVC

csharp
using DevExpress.DashboardWeb;
// ...
public class Global : System.Web.HttpApplication {
    protected void Application_Start(object sender, EventArgs e) {
        // ...
        DashboardConfigurator.Default.SetConnectionStringsProvider(new MyDataSourceWizardConnectionStringsProvider());
    }
    // ...
}
vb
Imports DevExpress.DashboardWeb
' ...
Public Class [Global]
    Inherits System.Web.HttpApplication
    Protected Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' ...
        DashboardConfigurator.Default.SetConnectionStringsProvider(New MyDataSourceWizardConnectionStringsProvider())
    End Sub
    ' ...
End Class

See the following help topic for more information: Manage Multi-Tenancy.

See Also

Prepare Data Source Storage

Custom Connection Strings for Data Sources