Spec-Zone .ru
спецификации, руководства, описания, API

22.2.5.11. Using the Connector/Net Interceptor Classes

An interceptor is a software design pattern that provides a transparent way to extend or modify some aspect of a program, similar to a user exit. No recompiling is required. With Connector/Net, the interceptors are enabled and disabled by updating the connection string to refer to different sets of interceptor classes that you instantiate.

Connector/Net includes the following interceptor classes:

Here are examples of using the FQN (fully qualified name) on the connection string:

MySqlConnection c1 = new MySqlConnection(@"server=localhost;pooling=false;commandinterceptors=CommandApp.MyCommandInterceptor,CommandApp");MySqlConnection c2 = new MySqlConnection(@"server=localhost;pooling=false;exceptioninterceptors=ExceptionStackTraceTest.MyExceptionInterceptor,ExceptionStackTraceTest");

In this example, the command interceptor is called CommandApp.MyCommandInterceptor and exists in the CommandApp assembly. The exception interceptor is called ExceptionStackTraceTest.MyExceptionInterceptor and exists in the ExceptionStackTraceTest assembly.

To shorten the connection string, you can register your exception interceptors in your app.config or web.config file like this:

<configSections><section name="MySQL" type="MySql.Data.MySqlClient.MySqlConfiguration, MySql.Data"/></configSections><MySQL><CommandInterceptors>  <add name="myC" type="CommandApp.MyCommandInterceptor,CommandApp" /></CommandInterceptors></MySQL><configSections><section name="MySQL" type="MySql.Data.MySqlClient.MySqlConfiguration, MySql.Data"/></configSections><MySQL><ExceptionInterceptors>  <add name="myE" type="ExceptionStackTraceTest.MyExceptionInterceptor,ExceptionStackTraceTest" /></ExceptionInterceptors></MySQL>

Once you have done that, your connection strings can look like these:

MySqlConnection c1 = new MySqlConnection(@"server=localhost;pooling=false;commandinterceptors=myC");MySqlConnection c2 = new MySqlConnection(@"server=localhost;pooling=false;exceptioninterceptors=myE");