IDBCommandInterceptor Interface
Allows you to intercept commands sent to a relational database.
Namespace: DevExpress.DataAccess.Sql
Assembly: DevExpress.DataAccess.v24.2.dll
Declaration
Remarks
Dashboard and report controls execute a variety of SQL statements against the database. Implement IDBCommandInterceptor
to intercept these data source commands. You can suppress a command or modify the execution algorithm.
You can register interceptors in service providers of dashboard or report controls. The registration method depends on the control type and platform:
- In Web dashboard applications, call the ASPxDashboard.SetDBCommandInterceptor(IDBCommandInterceptor) or DashboardConfigurator.SetDBCommandInterceptor(IDBCommandInterceptor) method.
- In WinForms dashboard applications, assign an
IDBCommandInterceptor
object to the control’sCustomDBCommandInterceptor
property. For example, use the DashboardDesigner.CustomDBCommandInterceptor property. - In Web reporting applications, register an
IDBCommandInterceptor
object as an extension inIServiceCollection
. - In WinForms reporting applications, call the XRDesignMdiController.AddService method.
Example: Reporting for WinForms - Override the Default Isolation Level
The following example shows how to override the default isolation level (READ COMMITTED) in a specific query. The change allows users to retrieve information without being locked by another process that modifies the same data. This way, the query consumes less memory.
- Implement the
IDBCommandInterceptor
interface (NolockInterceptor.cs
in this example). Call the IDBCommandInterceptor.CommandCreated(String, IDbCommand) method and specify CommandText to execute.
using DevExpress.DataAccess.Sql;
using System.Data;
namespace XtraReportApp {
internal class NolockInterceptor : IDBCommandInterceptor {
public void CommandCreated(string queryName, IDbCommand command) {
command.CommandText += " WITH (NOLOCK)";
}
}
}
- Call the XRDesignMdiController.AddService method to register the interceptor.
using DevExpress.DataAccess.Sql;
using System;
namespace XtraReportApp {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
reportDesigner1.AddService(typeof(IDBCommandInterceptor), new NolockInterceptor());
}
private void Form1_Load(object sender, EventArgs e) {
reportDesigner1.OpenReport(new XtraReport1());
}
}
}