Back to Devexpress

ASPxDashboard.ConfigureDataConnection Event

dashboard-devexpress-dot-dashboardweb-dot-aspxdashboard-07d3ff5a.md

latest16.1 KB
Original Source

ASPxDashboard.ConfigureDataConnection Event

Allows you to customize connection settings before the ASPxDashboard connects to a data store (database, OLAP cube, etc.).

Namespace : DevExpress.DashboardWeb

Assembly : DevExpress.Dashboard.v25.2.Web.WebForms.dll

NuGet Package : DevExpress.Web.Dashboard

Declaration

csharp
public event ConfigureDataConnectionWebEventHandler ConfigureDataConnection
vb
Public Event ConfigureDataConnection As ConfigureDataConnectionWebEventHandler

Event Data

The ConfigureDataConnection event's data class is ConfigureDataConnectionWebEventArgs. The following properties provide information specific to this event:

PropertyDescription
ConnectionNameGets the name of the connection for which the event has been raised. Inherited from ConfigureDataConnectionEventArgs.
ConnectionParametersGets or sets parameters used to establish a connection to data. Inherited from ConfigureDataConnectionEventArgs.
DashboardIdGets the identifier of the current dashboard.
DataSourceNameGets the data source name for which the event was raised. Inherited from DashboardConfigureDataConnectionEventArgs.

Remarks

The ConfigureDataConnection event is raised before the connection to a data store is established and allows you to customize connection settings.

To specify connection parameters, cast an object the e.ConnectionParameters property returns to the DataConnectionParametersBase descendant. The following table lists the different data sources and their corresponding descendants:

|

Data Source

|

Parameter Type

| | --- | --- | |

SQL Data Source

|

The SqlServerConnectionParametersBase class is the base type and defines the basic connection parameters: DatabaseName, Password, ServerName and UserName.

To specify other data provider parameters, cast an object to any of the types listed in the DevExpress.DataAccess.ConnectionParameters namespace. Here are some of the types:

You can also add a custom connection string. Cast an object to the CustomStringConnectionParameters class and assign a custom connection string to the ConnectionString property.

Tip

You can use a custom connection string to get data from an XML file that contains valid schema, for example, “xpoprovider=InMemoryDataStore;data source=””your_data_file.xml””;read only=True”

| |

OLAP Data Source

|

Cast an object to the OlapConnectionParameters type and use the ConnectionString property.

| |

Excel Data Source

|

Cast an object to the ExcelDataSourceConnectionParameters type and use the FileName and Password properties.

| |

Extract Data Source

|

Cast an object to the ExtractDataSourceConnectionParameters type and use the FileName and DriverName properties.

| |

Entity Framework Data Source

|

Event does not occur.

| |

Object Data Source

|

Event does not occur.

Handle the DataLoading / AsyncDataLoading event instead:

| |

JSON Data Source

|

Cast an object to the JsonSourceConnectionParameters type and use the JsonSource property.

You can also add a custom connection string. Cast an object to the CustomStringConnectionParameters class and assign a custom connection string to the ConnectionString property.

| |

MongoDB Data Source

|

Cast an object to the MongoDBCustomConnectionParameters type and use the following connection parameters:

|

Tip

Refer to the following topic for information about custom connection strings: Custom Connection Strings for Data Sources

This event is raised when the dashboard is supplied with data using one of the following data source types:

Note

If the dashboard is supplied with data using the DashboardObjectDataSource data source, the ASPxDashboard.DataLoading event is fired instead.

The following code snippet shows how to configure data connections for SQLite, Excel, and OLAP data sources:

csharp
private void ASPxDashboard1_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
    if (e.ConnectionName == "sqliteConnection") {
        SQLiteConnectionParameters sqliteParams = new SQLiteConnectionParameters();
        sqliteParams.FileName = "file:Data/nwind.db";
        e.ConnectionParameters = sqliteParams;
    }
    if (e.ConnectionName == "olapConnection") {
        OlapConnectionParameters olapParams = new OlapConnectionParameters();
        olapParams.ConnectionString = "Provider=MSOLAP;Data Source=http://demos.devexpress.com/Services/OLAP/msmdpump.dll;"
            + "Initial catalog=Adventure Works DW Standard Edition;Cube name=Adventure Works;Query Timeout=100;";
        e.ConnectionParameters = olapParams;
    }
    if (e.DataSourceName == "Excel Data Source") {
        ExcelDataSourceConnectionParameters excelParams = new ExcelDataSourceConnectionParameters(HttpContext.Current.Server.MapPath("App_Data/Sales.xlsx"));
        e.ConnectionParameters = excelParams;
    }
}
vb
Private Sub ASPxDashboard1_ConfigureDataConnection(ByVal sender As Object, ByVal e As ConfigureDataConnectionWebEventArgs)
    If e.ConnectionName = "sqliteConnection" Then
        Dim sqliteParams As New SQLiteConnectionParameters()
        sqliteParams.FileName = "file:Data/nwind.db"
        e.ConnectionParameters = sqliteParams
    End If
    If e.ConnectionName = "olapConnection" Then
        Dim olapParams As New OlapConnectionParameters()
        olapParams.ConnectionString = "Provider=MSOLAP;Data Source=http://demos.devexpress.com/Services/OLAP/msmdpump.dll;" & 
            "Initial catalog=Adventure Works DW Standard Edition;Cube name=Adventure Works;Query Timeout=100;"
        e.ConnectionParameters = olapParams
    End If
    If e.DataSourceName = "Excel Data Source" Then
        Dim excelParams As New ExcelDataSourceConnectionParameters(HttpContext.Current.Server.MapPath("App_Data/Sales.xlsx"))
        e.ConnectionParameters = excelParams
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the ConfigureDataConnection event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-web-forms-dashboard-register-data-sources/CS/WebFormsDashboardDataSources/Pages/OlapDashboard.aspx.cs#L25

csharp
ASPxDashboardOlap.ConfigureDataConnection += ASPxDashboardOlap_ConfigureDataConnection;

web-forms-dashboard-handle-errors/CS/WebFormsCustomTextForInternalDashboardErrors/WebForm1.aspx.cs#L30

csharp
ASPxDashboard1.SetDataSourceStorage(dataSourceStrorage);
    ASPxDashboard1.ConfigureDataConnection += ASPxDashboard1_ConfigureDataConnection;
}

asp-net-web-forms-dashboard-register-data-sources/VB/WebFormsDashboardDataSources/Pages/OlapDashboard.aspx.vb#L23

vb
ASPxDashboardOlap.SetDataSourceStorage(dataSourceStorage)
AddHandler ASPxDashboardOlap.ConfigureDataConnection, AddressOf Me.ASPxDashboardOlap_ConfigureDataConnection
ASPxDashboardOlap.InitialDashboardId = "dashboardOlap"

web-forms-dashboard-handle-errors/VB/WebFormsCustomTextForInternalDashboardErrors/WebForm1.aspx.vb#L32

vb
ASPxDashboard1.SetDataSourceStorage(dataSourceStrorage)
    AddHandler ASPxDashboard1.ConfigureDataConnection, AddressOf Me.ASPxDashboard1_ConfigureDataConnection
End Sub

See Also

ASPxDashboard Class

ASPxDashboard Members

DevExpress.DashboardWeb Namespace