Skip to content

Non SQL Server Provider Configuration

Rick Strahl edited this page Jun 27, 2015 · 6 revisions

By default the resource providers and manager use SQL Server to hold the database resources. If you don't do any custom configuration in code to specify the Configuration.DbResourceDataManagerType you'll get the Sql Server provider/manager.

However, all of the following providers are supported:

  • Sql Server (2008, 2012, Express, Azure(?))
  • Sql Server Compact
  • MySql
  • SqLite

As mentioned previously there is very little database access that actually happens when running the application, so even local databases like SqLite or Sql Compact can be used.

To use a provider other than Sql Server you need to do the following:

  • Add the appropriate Westwind.Globalization. assembly/NuGet Package
  • Specify the Configuration.DbResourceDataManagerType

Sql Server

no additional package needed

// not required - use only if you need to reset provider in code
DbResourceConfiguration.Current.DbResourceDataManagerType = typeof(DbResourceSqlServerDataManager);
Connection String Example:
<add name="SqlServerLocalizations" connectionString="server=.;database=localizations;integrated security=true;" providerName="System.Data.SqlClient" />

Sql Server Compact

add NuGet Package: Microsoft.SqlServer.Compact

DbResourceConfiguration.Current.DbResourceDataManagerType = typeof(DbResourceSqlServerCeDataManager);
Connection String Example:
<add name="SqlServerCeLocalizations" connectionString="Data Source=|DataDirectory|\Localizations.sdf;Persist Security Info=False;" providerName="System.Data.SqlServerCe.4.0" />
<add name="Localizations" connectionString="server=.;database=localizations;integrated security=true;" providerName="System.Data.SqlClient" />

MySql

add NuGet Package: MySql.Data

DbResourceConfiguration.Current.DbResourceDataManagerType = typeof (DbResourceMySqlDataManager);
Connection String Example:
<add name="MySqlLocalizations" connectionString="server=localhost;uid=testuser;pwd=super10seekrit;database=Localizations" providerName="MySql.Data.MySqlClient" />

SqLite

add NuGet Package: System.Data.SQLite.Core

DbResourceConfiguration.Current.DbResourceDataManagerType = typeof(DbResourceSqLiteDataManager);
Connection String Example:
<add name="SqLiteLocalizations" connectionString="Data Source=|DataDirectory|\SqLiteLocalizations.db;Version=3" providerName="System.Data.SQLite" />

Global Data Manager Configuration

This code configures the data manager globally so every time a data access operation occurs it instantiates the data manager configured here. It's important that you add the appropriate assembly first, otherwise these provider types will not be available and your code won't compile.

ADO.NET Provider Configuration

The following configuration settings for each of the providers should be handled when the NuGet packages are installed, but in case you're manually adding references, or updating a project manually you will also need to add the following ADO.NET Resource Provider configuration settings in your web.config or app.config file:

<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
</configuration>