SqlDataSource.ConfigureDataConnection Event
Allows you to customize connection settings before connecting to a database.
Namespace: DevExpress.DataAccess.Sql
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
Event Data
The ConfigureDataConnection event's data class is ConfigureDataConnectionEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
ConnectionName | Gets the name of the connection for which the event has been raised. |
ConnectionParameters | Gets or sets parameters used to establish a connection to data. |
Remarks
The ConfigureDataConnection event occurs only if the SqlDataSource.ConnectionParameters property is set. The event is not raised if the ConnectionName was configured instead. The ConfigureDataConnection event fires each time the SqlDataSource connects to a database. Handle this event to change parameters required to establish a connection to data (for instance, the server name, the database name, user credentials, the path to a data file, etc.).
Tip
For more information, review the following article: SqlDataSource - How to change connection parameters at runtime.
Use the event parameter’s ConfigureDataConnectionEventArgs.ConnectionName property to identify the connection for which the event is raised. To access connection parameters, use the ConfigureDataConnectionEventArgs.ConnectionParameters property.
The ConfigureDataConnectionEventArgs.ConnectionParameters property returns a DataConnectionParametersBase descendant. Different DataConnectionParametersBase descendants provide connection parameters for different DBMS and data file formats. For instance, the MsSqlConnectionParameters, OracleConnectionParameters, XmlFileConnectionParameters and many other classes are available.
To edit current connection parameters, cast the returned DataConnectionParametersBase object to an appropriate descendant type and then adjust the parameters. To change the data provider, create an object of an appropriate descendant type, customize the parameters and assign the created object to the ConfigureDataConnectionEventArgs.ConnectionParameters property.