Register Default Data Connections

  • 3 min to read

This document describes how to provide a Web Dashboard with a set of data connections. These connections are available in the Dashboard Data Source Wizard when users create new data sources.

WebDesigner_DefaultDataConnections

To create a data connection, add a connection string to the Web.config file or specify a data connection provider:

Add a Connection String to Web.config

A connection string should contain the XpoProvider parameter that depends on the database type:

<configuration>
    <connectionStrings>
        <add name="nwindConnection" connectionString="XpoProvider=MSSqlServer; data source=localhost; initial catalog=Northwind; integrated security=SSPI;" />
    </connectionStrings>
</configuration>

See Custom Connection Strings for Data Sources for information on how to specify a custom connection string.

The Web Dashboard control does not pass connection string names to the client. If users create a new data source in the Data Source Wizard, an exception occurs on an attempt to load connection strings. Pass the ConfigFileConnectionStringsProvider instance as the ASPxDashboard.SetConnectionStringsProvider method's parameter to allow users to create new data sources based on available connection strings from the Web.config file:

ASPxDashboard1.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider());

The Dashboard Data Source Wizard can also display inherited connection strings (for instance, connection strings from machine.config). To remove strings from machine.config, add the clear element before the application's connection strings:

<connectionStrings>
    <clear/>
    ...
</connectionStrings>

Specify a Data Connection Provider

Use the ASPxDashboard.SetConnectionStringsProvider or DashboardConfigurator.SetConnectionStringsProvider method to specify a data connection provider - the type of method depends on the control's server-side API.

This example shows how to implement a custom provider of connection strings 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.Add("msAccessConnection", "MS Access Connection");
            connections.Add("msSqlConnection", "MS SQL Connection");
            return connections;
        }

        public DataConnectionParametersBase GetDataConnectionParameters(string name) {
            // Return custom connection parameters for the custom connection.
            if (name == "msAccessConnection") {
                return new Access97ConnectionParameters("|DataDirectory|nwind.mdb", "", "");
            } else if (name == "msSqlConnection") { 
                return new MsSqlConnectionParameters("localhost", "Northwind", "", "", MsSqlAuthorizationType.Windows);
            } 
            throw new System.Exception("The connection string is undefined.");
        }
    }

After you have implemented a custom provider of connection strings, pass the instance of this class to the ASPxDashboard.SetConnectionStringsProvider method.

using DevExpress.DashboardWeb;
// ...
public partial class WebForm1 : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {
        // ...
        ASPxDashboard1.SetConnectionStringsProvider(new MyDataSourceWizardConnectionStringsProvider());
    }
    // ...
}
See Also