Skip to content

Connection string provider names

Wade Baglin edited this page Sep 14, 2020 · 4 revisions

Depending on how you construct PetaPoco you may need a valid provider name. A provider name simply allows PetaPoco to choose the correct DB provider to use. A provider name most common use is with web/app configuration file connection strings.

Traditionally, the provider name section in a web/app connection strings section of the configuration file would contain the invariant name of the provider's DB factory invariant="FirebirdSql.Data.FirebirdClient". However, as PetaPoco DB provider factories are known at runtime it's not needed. That said, all the provider invariant factory names will work, but there's also shorthand versions, below, which PetaPoco will accept.

  • A provider name is how PetaPoco maps a connection string to the correct DB Provider.
  • Invariant provider factory names still work
  • Shorter names are available

Connection strings

Sample connection strings:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <clear />
    <add name="postgres"          
         providerName="Npgsql" connectionString="Host=127.0.0.1;Username=petapoco;Password=petapoco;Database=petapoco;Port=5001" />
    <add name="mysql"
         providerName="MySql.Data.MySqlClient" connectionString="Server=127.0.0.1;Uid=petapoco;Pwd=petapoco;Database=petapoco;Port=5002" />
    <add name="mysqlconnector"
         providerName="MySqlConnector" connectionString="Server=127.0.0.1;Uid=petapoco;Pwd=petapoco;Database=petapoco;Port=5002" />
    <add name="mariadb"
         providerName="MySql.Data.MySqlClient" connectionString="Server=127.0.0.1;Uid=petapoco;Pwd=petapoco;Database=petapoco;Port=5003"  />
    <add name="sqlite"
         providerName="System.Data.SQLite" connectionString="Data Source=PetaPoco.sqlite;Version=3;" />
    <add name="mssqlce"
         providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=petapoco.sdf"  />
    <add name="mssql"
         providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|Databases\MSSQL\petapoco.mdf;Integrated Security=True;User Instance=True"  />
    <add name="mssqlmsdata"
         providerName="Microsoft.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|Databases\MSSQL\petapoco.mdf;Integrated Security=True;User Instance=True"  />
    <add name="firebird"
         providerName="FirebirdSql.Data.FirebirdClient" connectionString="User=SYSDBA;Password=masterkey;Database=/databases/petapoco.fdb;DataSource=localhost;Port=5004;ServerType=0;Charset=NONE;"  />
    <add name="msaccess"
         providerName="OleDb" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Databases\MSAccess\petapoco.accdb" />
  </connectionStrings>
</configuration>

Provider names

Valid provider names are:

Provider Accepted provider names Other
SqlServerDatabaseProvider SqlServer, System.Data.SqlClient Is the default
SqlSererMsDataDatabaseProvider Microsoft.Data.SqlClient
MySqlDatabaseProvider MySql, MySql.Data.MySqlClient
MySqlConnector MySqlConnector
MariaDbDatabaseProvider MariaDb May use MySql provider
PostgreSQLDatabaseProvider Npgsql, pgsql
SQLiteDatabaseProvider SQLite, System.Data.SQLite
SqlServerCEDatabaseProviders SqlServerCe, SqlCeConnection, System.Data.SqlServerCe.4.0
OracleDatabaseProvider Oracle, Oracle.ManagedDataAccess.Client
MsAccessDbDatabaseProvider OLEDB Connection string must have either Microsoft.ACE.OLEDB.12.0 or Microsoft.Jet.OLEDB.4.0
FirebirdDbDatabaseProvider Firebird, FbConnection beta

Sample provider name in use.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="SomeName" connectionString="SomeConnectionString" providerName="Npgsql"/>
  </connectionStrings>
</configuration>

Note: the casing of the provider name does not matter.