---
title: Custom Data provider example
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

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

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.

> **Note:** **Customizing live site projects**
>
> Deploy the assembly containing the custom provider to your live site application, in addition to the Xperience administration application. This ensures that the customization applies when loading or modifying data in the live site application.

## Implementing a custom IDataProvider instance

The recommended approach is to create and register a custom implementation of the **IDataProvider** interface.

```csharp

using CMS;
using CMS.Core;
using CMS.DataEngine;
using CMS.DataProviderSQL;

// Registers the custom implementation of IDataProvider
// Set the 'Lifestyle.Transient' lifetime when registering the IDataProvider implementation
[assembly: RegisterImplementation(typeof(IDataProvider), typeof(CustomDataProvider), Lifestyle = Lifestyle.Transient)]

public class CustomDataProvider : IDataProvider
{
    public IDataConnection GetNewConnection(string connectionString)
    {
        ...
    }
}

```

## Adding a custom data provider assembly (obsolete)

You can create a custom data provide assembly and register it via the **CMSDataProviderAssembly** web.config key.

1. Open your administration solution in Visual Studio.
2. Add a new **Class Library** project to the solution, for example named _CustomDataProvider_.
3. Add the Xperience API libraries to the new project:

   1. Right-click the solution in the **Solution Explorer** and select **Manage NuGet Packages for Solution**.
   2. Select the **Kentico.Xperience.Libraries** package.
   3. Install the package into the custom project (the version must match your MVC project's _Kentico.Xperience.AspNet.Mvc5_ package and the exact hotfix version of your Xperience administration project).
4. Reference the _CustomDataProvider_ project from the Xperience web project (_CMSApp_).
5. Open your Xperience program files directory (by default _C:\Program Files\Kentico\\_) and expand the _CodeSamples\CustomizationSamples\CustomDataProvider_ subfolder.
6. Copy the following files into the _CustomDataProvider_ directory in your web project:
   - **DataConnection.cs**
   - **DataProvider.cs**
   - **SqlGenerator.cs**
   - **TableManager.cs**
7. Include the new files into the _CustomDataProvider_ project in Visual Studio:
   1. Expand the _CustomDataProvider_ project in the Solution Explorer.
   2. Click **Show all files** at the top of the Solution Explorer.
   3. Select the new files while holding the **Ctrl** key.
   4. Right-click one of the files and select **Include in Project**.
8. Edit the copied files and rename the namespaces to **exactly** match the assembly name of your custom project (_CustomDataProvider_ in this example).
9. Rebuild the solution.

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:

   ```html

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

   ```

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

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