Skip to main content
A newer version of this page is available. .

Register Default Data Connections

  • 3 minutes to read

This document describes how to provide a Web Dashboard with a set of predefined data connections. These connections will be displayed for end-users in the Dashboard Data Source Wizard when creating new data sources.

WebDesigner_DefaultDataConnections

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 Web.config file as shown below:

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

    The connection string should contain the XpoProvider parameter that depends on the used database type. See Custom Connection Strings for the SQL Data Source for information on how to specify the XpoProvider parameter.

    The Web Dashboard control does not pass connection string names to the client by default. Creating a new data source in the Data Source Wizard raises an exception on an attempt to load connection strings. Pass the ConfigFileConnectionStringsProvider instance as the SetConnectionStringsProvider method’s parameter to allow creating new data sources based on connection strings from the Web.config file:

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

    Tip

    The Data Source wizard can display not only connection strings contained in the Web.config file but inherited connection strings, too (for instance, connection strings from machine.config). To remove such strings, add the clear element before the application’s connection strings.

    <connectionStrings>
        <clear/>
        ...
      </connectionStrings>
    
  • Specify a provider of data connections using the DashboardConfigurator.SetConnectionStringsProvider method.

    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 DashboardConfigurator.SetConnectionStringsProvider method.

    using DevExpress.DashboardWeb;
    // ...
        public class Global : System.Web.HttpApplication
        {
            protected void Application_Start(object sender, EventArgs e)
            {
                // ...
                DashboardConfigurator.Default.SetConnectionStringsProvider(new MyDataSourceWizardConnectionStringsProvider());
            }
            // ...
        }
    }