corelibraries-devexpress-dot-dataaccess-dot-sql-98452b10.md
Allows you to intercept operations on a connection to a database.
Namespace : DevExpress.DataAccess.Sql
Assembly : DevExpress.DataAccess.v25.2.dll
NuGet Package : DevExpress.DataAccess
public interface IDBConnectionInterceptor
Public Interface IDBConnectionInterceptor
The following members return IDBConnectionInterceptor objects:
Implement IDBConnectionInterceptor to intercept, modify, and/or suppress SQL operations. The list includes low-level database operations such as executing a command or setting a key-value pair in a session context. Once the connection is open, you can store values in the session context and execute any request you require.
You can register an interceptor in dashboard and report control service providers. The registration method depends on the control type and platform:
IDBConnectionInterceptor object to the control’s CustomDBConnectionInterceptor property. For example, use the DashboardDesigner.CustomDBConnectionInterceptor property.IDBConnectionInterceptor object as an extension in IServiceCollection.This example shows how you can implement connection filtering in an application where users (tenants) share the same SQL Server user. Once the application connects to the database, it stores the current user ID in SESSION_CONTEXT. Security policies filter rows that shouldn’t be visible to this ID.
Refer to the following example for complete source code that implements the scenario listed above:
The following image displays the registration form where you can select a user to see the dashboard that displays filtered data based on your selection.
The following code snippet shows how to implement IDBConnectionInterceptor that filters data when the application connects to the database:
Implement the IDBConnectionInterceptor interface (RLSConnectionInterceptor.cs in this example). When the database connection opens, store the current user ID in SESSION_CONTEXT. Modify queries to the Order table - filter data by user ID. This way you implement database behavior equivalent to connection filtering.
Register the interceptor in DashboardConfigurator.
View Example: Reporting for ASP NET.Core - Implement Row-Level Security
See Also