Skip to main content

IDataSourceWizardConnectionStringsProvider Interface

Allows you to manage data connections available in the Data Source Wizard.

Namespace: DevExpress.DataAccess.Web

Assembly: DevExpress.DataAccess.v24.1.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

Declaration

public interface IDataSourceWizardConnectionStringsProvider

Remarks

The Web End-User Report Designer and Web Dashboard components allow users to invoke the Data Source Wizard to connect to databases. For more information, review the following help topics:

The IDataSourceWizardConnectionStringsProvider interface allows you to implement a service that suppplies connection strings to display available data sources in the Data Source Wizard. The service can also specify connection parameters for the newly created data source. The connection parameters are serialized and stored along with the report bound to that data source.

If you do not wish to serialize and store connection parameters, return null in the GetDataConnectionParameters(String) method, and implement the IConnectionProviderFactory service.

Examples

The following table lists topics with the IDataSourceWizardConnectionStringsProvider interface implementation for different components and platforms.

Dashboards Reports
Register Default Data Connections (ASP.NET Web Forms) Register Data Connections (ASP.NET Web Forms)
Register Default Data Connections (Web) Register Connections (ASP.NET Core)

The IDataSourceWizardConnectionStringsProvider interface is intended for use only with SQL data sources. For information on how to add different data source types, review the topics listed below:

Dashboard Reports
Prepare Data Source Storage in ASP.NET Web Forms Register Predefined Data Sources (Web Forms)
Prepare Data Source Storage (Web) Register Predefined Data Sources (ASP.NET Core)

Example - Security Practice

View Example: Dashboard for ASP.NET Core - How to implement multi-tenant Dashboard architecture

The following IDataSourceWizardConnectionStringsProvider implementation shows how to specify connection strings depending on the user access rights:

using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Web;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;

public class CustomConnectionStringProvider : IDataSourceWizardConnectionStringsProvider {
    private readonly IHttpContextAccessor contextAccessor;
    private Dictionary<string, string> connectionStrings = new Dictionary<string, string>();

    public CustomConnectionStringProvider(IHttpContextAccessor contextAccessor) {
        this.contextAccessor = contextAccessor;
        connectionStrings.Add("NorthwindConnectionString", @"XpoProvider=SQLite; Data Source=App_Data/nwind.db;");
        connectionStrings.Add("CarsXtraSchedulingConnectionString", @"XpoProvider=SQLite;Data Source=App_Data/CarsDB.db;");
    }

    public Dictionary<string, string> GetConnectionDescriptions() {
        var connections = new Dictionary<string, string>();
        var userName = contextAccessor.HttpContext.Session.GetString("CurrentUser");

        if (userName == "Admin") {
            connections.Add("NorthwindConnectionString", "Northwind Connection");
            connections.Add("CarsXtraSchedulingConnectionString", "CarsXtraScheduling Connection");
        }
        else if (userName == "User") {
            connections.Add("CarsXtraSchedulingConnectionString", "CarsXtraScheduling Connection");
        }

        return connections;
    }

    public DataConnectionParametersBase GetDataConnectionParameters(string name) {
        if (GetConnectionDescriptions().ContainsKey(name)) {
            return new CustomStringConnectionParameters(connectionStrings[name]);
        }
        else {
            throw new System.ApplicationException("You are not authorized to use this connection.");
        }
    }
}
See Also