Custom Data provider example

Customization of the data provider allows you to implement your own database connector.

You cannot modify the data provider in the App_Code folder. The customizations must be added as part of a new assembly, which you then need to register via the CMSDataProviderAssembly web.config key.

Custom data providers are not intended for accessing non-Microsoft SQL Server database engines. They only allow you to modify how queries are executed against the Microsoft SQL Server.

Adding the custom data provider assembly

  1. Copy the CustomDataProvider project from your Kentico installation directory (typically C:\Program Files\Kentico\<version>\CodeSamples\CustomDataProvider) to a development folder.

  2. Open your web project in Visual Studio (using the WebSite.sln/WebApp.sln file).

  3. Click File -> Add -> Existing Project and select CustomDataProvider.csproj in the folder where you copied the CustomDataProvider project.

  4. Unfold the References section of the CustomDataProvider project and delete all invalid references.

  5. Right-click the CustomDataProvider project and select Add Reference.

  6. Open the Browse tab of the Reference manager dialog, click Browse and navigate to the Lib folder of your Kentico web project.

  7. Add references to the following libraries:

    • CMS.Base.dll
    • CMS.DataEngine.dll
    • CMS.Helpers.dll
  8. Right‑click the main Kentico website object (or the CMSApp project if your installation is a web application) and select Add Reference.

  9. Open the Solution -> Projects tab and add a reference to the CustomDataProvider project.

  10. Rebuild the CustomDataProvider project.

The CustomDataProvider project is now integrated into your application. By default, the classes in the custom data provider are identical to the ones used by default, but you can modify them according to your own requirements.

Registering the custom data provider

  1. Edit your application’s web.config file.

  2. Add the following key to the configuration/appSettings section:

    
    
    
     <add key="CMSDataProviderAssembly" value="CMS.CustomDataProvider"/>
    
    
     

The system loads the DataProvider class from the namespace specified as the value of the CMSDataProviderAssembly key.

Your application now uses the custom data provider for handling database operations.