Back to Devexpress

IDBCommandInterceptor Interface

corelibraries-devexpress-dot-dataaccess-dot-sql-ec724951.md

latest5.7 KB
Original Source

IDBCommandInterceptor Interface

Allows you to intercept commands sent to a relational database.

Namespace : DevExpress.DataAccess.Sql

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public interface IDBCommandInterceptor
vb
Public Interface IDBCommandInterceptor

The following members return IDBCommandInterceptor objects:

LibraryRelated API Members
WinForms ControlsEditQueryContext.CommandInterceptor
DashboardDashboardDesigner.CustomDBCommandInterceptor
DashboardViewer.CustomDBCommandInterceptor
IDashboardControl.CustomDBCommandInterceptor

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:

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.

View Example

  1. Implement the IDBCommandInterceptor interface (NolockInterceptor.cs in this example). Call the IDBCommandInterceptor.CommandCreated(String, IDbCommand) method and specify CommandText to execute.
csharp
using DevExpress.DataAccess.Sql;
using System.Data;

namespace XtraReportApp {
    internal class NolockInterceptor : IDBCommandInterceptor {
        public void CommandCreated(string queryName, IDbCommand command) {
            command.CommandText += " WITH (NOLOCK)";
        }
    }
}
vb
Imports DevExpress.DataAccess.Sql
Imports System.Data

Namespace XtraReportApp
    Friend Class NolockInterceptor
        Inherits IDBCommandInterceptor

        Public Sub CommandCreated(ByVal queryName As String, ByVal command As IDbCommand)
            command.CommandText &= " WITH (NOLOCK)"
        End Sub
    End Class
End Namespace
  1. Call the XRDesignMdiController.AddService method to register the interceptor.
csharp
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());
        }
    }
}
vb
Imports DevExpress.DataAccess.Sql
Imports System

Namespace XtraReportApp
    Partial Public Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            InitializeComponent()
            reportDesigner1.AddService(GetType(IDBCommandInterceptor), New NolockInterceptor())
        End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            reportDesigner1.OpenReport(New XtraReport1())
        End Sub
    End Class
End Namespace

See Also

IDBCommandInterceptor Members

DevExpress.DataAccess.Sql Namespace