Skip to content
Igor Tkachev edited this page May 20, 2016 · 1 revision

Home / Data

The BLToolkit.DbManager component is a data provider independent wrapper for ADO.NET. It means that the DbManager does not use any specific data source classes such as SqlConnection, SqlCommand, etc. It uses common classes and interfaces instead. All data source specific logic is encapsulated in special classes called DataProviders.

The following table lists providers available with BLToolkit:

Class Provider Name Namespace Vendor
AccessDataProvider Access System.Data.OleDb Microsoft
OdbcDataProvider Odbc System.Data.Odbc Microsoft
OleDbDataProvider OleDb System.Data.OleDb Microsoft
OracleDataProvider Oracle System.Data.OracleClient Microsoft (deprecated by Microsoft in FW 4.0)
SqlDataProvider Sql System.Data.SqlClient Microsoft
DB2DataProvider DB2 IBM.Data.DB2 IBM
FdpDataProvider Fdp FirebirdSql.Data.FirebirdClient Firebird
InformixDataProvider Informix IBM.Data.Informix IBM
MySqlDataProvider MySql MySql.Data.MySqlClient Sun Microsystems
OdpDataProvider ODP Oracle.DataAccess.Client Oracle
SqlCeDataProvider SqlCe System.Data.SqlServerCe Microsoft
SQLiteDataProvider SQLite System.Data.SQLite SQLite.org
SybaseAdoDataProvider SybaseAdo System.Data.OleDb Support for DataDirect Sybase ADO Provider
SybaseDataProvider Sybase ASE Sybase.Data.AseClient Sybase

The first five providers are preregistered in the library and are ready to use. The remaining providers need additional configuration as they require references to 3rd party components.

You can add a listed above or your own data provider into your project and register it as shown below:

AddDataProvider.cs

using System;

using NUnit.Framework;

using BLToolkit.Data;
using BLToolkit.Data.DataProvider;

namespace HowTo.Data.DataProvider
{
    [TestFixture]
    public class AddDataProvider
    {
        const string connectionString = 
            "Provider=ASEOLEDB;Data Source=server;Catalog=database;User Id=user;Password=pwd;";

        [Test]
        public void Test()
        {
            // 3rd party data provider registration.
            //
            DbManager.AddDataProvider(new SybaseAdoDataProvider());

            // It can be configured by App.config.
            // We use this way for the demo purpose only.
            //
            DbManager.AddConnectionString(
                "SybaseAdo",       // Provider name
                "Default",         // Configuration
                connectionString); // Connection string

            using (DbManager db = new DbManager("SybaseAdo", "Default"))
            {
            }
        }
    }
}

Also a data provider can be registered by configuration file:

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <add
            name             = "DemoConnection"
            connectionString = "Server=.;Database=BLToolkitData;Integrated Security=SSPI"
            providerName     = "System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Also you can use BLToolkit config section.

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="bltoolkit" type="BLToolkit.Configuration.BLToolkitSection, BLToolkit.3"/>
    </configSections>
    <bltoolkit>
        <dataProviders>
            <add type="BLToolkit.Data.DataProvider.DB2DataProvider,        UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.FdpDataProvider,        UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.InformixDataProvider,   UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.MySqlDataProvider,      UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.OdpDataProvider,        UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.PostgreSQLDataProvider, UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.SqlCeDataProvider,      UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.SQLiteDataProvider,     UnitTests.Linq" />
            <add type="BLToolkit.Data.DataProvider.SybaseDataProvider,     UnitTests.Linq" />
        </dataProviders>
    </bltoolkit>
    <connectionStrings>
        <add name="Access"     connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Data\BLToolkitData.mdb;Locale Identifier=1033;Jet OLEDB:Engine Type=5;Persist Security Info=True"/>
        <add name="DB2"        connectionString="Server=DBHost:50000;Database=BLTD;UID=TestUser;PWD=TestPassword;" providerName="IBM.Data.DB2"/>
        <add name="Fdp"        connectionString="DataSource=DBHost;Database=C:\Data\BLToolkitData.fb2;User Id=SYSDBA;Password=masterkey"/>
        <add name="Informix"   connectionString="Host=DBHost;Service=9090;Server=ol_ids_1150_1;Protocol=onsoctcp;Database=BLToolkitData;UID=sysmaster;PWD=TestPassword;" providerName="IBM.Data.Informix"/>
        <add name="MySql"      connectionString="Server=DBHost;Port=3306;Database=bltoolkitdata;Uid=root;Pwd=TestPassword;" providerName="MySql.Data.MySqlClient"/>
        <add name="Oracle"     connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DBHost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User Id=TestUser;Password=TestPassword;" providerName="Oracle.DataAccess.Client"/>
        <add name="PostgreSQL" connectionString="Server=DBHost;Port=5432;Database=BLToolkitData;User Id=postgres;Password=TestPassword;" providerName="Npgsql"/>
        <add name="Sql2008"    connectionString="Server=.;Database=BLToolkitData;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
        <add name="Sql2005"    connectionString="Server=DBHost;Database=BLToolkitData;User Id=TestUser;Password=TestPassword;" providerName="System.Data.SqlClient"/>
        <add name="SqlCe"      connectionString="Data Source=..\..\..\..\Data\BLToolkitData.sdf"/>
        <add name="SQLite"     connectionString="Data Source=..\..\..\..\Data\BLToolkitData.sqlite"/>
        <add name="Sybase"     connectionString="Data Source=DBHost;Port=5000;Database=BLToolkitData;Uid=sa" providerName="Sybase.Data.AseClient"/>
        <add name="Northwind"  connectionString="Data Source=.;Database=Northwind;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
    </connectionStrings>
</configuration>

Here UnitTests.Linq assembly name should be replaces by your own.

Clone this wiki locally