Skip to main content
All docs
V24.2

Save Connection Parameters

  • 4 minutes to read

The Dashboard Designer does not save the username and password automatically after a successful connection to a database. For security reasons, the Dashboard Designer prompts a user to enter credentials for each connection because the dashboard definition does not encrypt credentials. If you want the application to connect to a database without user interaction, use one of the following techniques:

  • Save database credentials in a dashboard definition.

    This technique is suitable for a development environment because stored credentials are not encrypted. We recommend that you use a different technique that allows you to implement more flexible security models in a production environment.

  • Specify connection parameters in code before a dashboard is opened.

    This technique allows you to specify connection parameters obtained from an external source in a ConfigurationDataConnection event handler.

  • Use Windows Authentication mode.

    This technique disables SQL Server Authentication and allows a user to connect through a Windows user account.

Save Database Credentials in a Dashboard Definition

To save database credentials in a dashboard definition, set the SqlWizardSettings.DatabaseCredentialsSavingBehavior property to one of the following values:

Always
Database credentials are always serialized with document layouts. Users cannot change this behavior.
Prompt

Users can select whether to save database credentials in the Data Source wizard. The following dialog appears once a user specifies connection parameters and clicks Next:

DataSourceWizard_SaveConnectionString

Refer to the following help topic for more information on how to create a connection to SQL databases in the Data Source Wizard: Connecting to SQL Databases.

If you do not want to store connection parameters in a dashboard, handle the DashboardDesigner.DashboardSaving event to remove connection parameters before a dashboard is saved. Then, implement another connection parameter storage mechanism as described in the sections below.

The code snippets below show how you can clear Oracle database connection parameters from a dashboard xml file before a dashboard is saved:

  • Assign a new DevExpress.DataAccess.ConnectionParameters.OracleConnectionParameters instance to the SqlDataSource.ConnectionParameters property to clear out connection information.

    using DevExpress.DataAccess;
    using DevExpress.DashboardCommon;
    //...
    private void dashboardDesigner1_DashboardSaving(object sender, DevExpress.DashboardWin.DashboardSavingEventArgs e){  
        DashboardSqlDataSource dataSource = e.Dashboard.DataSources[0] as DashboardSqlDataSource;  
        dataSource.ConnectionParameters = new OracleConnectionParameters();  
    }  
    
  • Use the DataConnectionBase.StoreConnectionNameOnly property to store only the data connection’s name.

    using DevExpress.DataAccess;
    using DevExpress.DashboardCommon;
    //...
    private void dashboardDesigner1_DashboardSaving(object sender, DevExpress.DashboardWin.DashboardSavingEventArgs e){
        foreach (DashboardSqlDataSource ds in e.Dashboard.DataSources.OfType<DashboardSqlDataSource>())
            (ds.Connection as DataConnectionBase).StoreConnectionNameOnly = true;
    }
    

Pass Connection Parameters in Code

The DashboardDesigner.ConfigureDataConnection event allows you to pass authentication credentials used to connect the Dashboard Designer to a database without user interaction. The event occurs before the Dashboard Designer connects to a data store.

To specify connection parameters, cast the e.ConnectionParameters property value to a DataConnectionParametersBase descendant.

The following code snippet shows how to connect to an Oracle database before the dashboard is loaded:

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.ConnectionParameters;
//...
private void DashboardDesigner_ConfigureDataConnection(object sender, DashboardConfigureDataConnectionEventArgs e){
    OracleConnectionParameters parameters = e.ConnectionParameters as OracleConnectionParameters;
        if (parameters != null){
            parameters.ProviderType = OracleProviderType.ODPManaged;
            parameters.ServerName = "dashboarddb:1521/OracleTest";
            parameters.UserName = "northwind";
            parameters.Password = "test";
        }
}

Windows Authentication Mode

This mode enables Windows Authentication and disables SQL Server Authentication. When a user uses a Windows account to authenticate in an SQL Server, the Windows principal token is used to validate the account name and password. The SQL server does not request a password or perform identity validation because the operating system confirms the user identity.

Windows Authentication mode is available for databases deployed on the Microsoft SQL Server.

The Data Source Wizard allows users to select the Authentication type in the following dialog:

DataSourceWizard MSSQL Server

In code, set the MsSqlConnectionParameters.AuthorizationType property to Windows:

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
// ...
    MsSqlConnectionParameters msSqlParams = new MsSqlConnectionParameters();
    msSqlParams.AuthorizationType = MsSqlAuthorizationType.Windows;
    msSqlParams.ServerName = "localhost";
    msSqlParams.DatabaseName = "Northwind";

    DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("Data Source 1", msSqlParams);
//...