s.k.paul
s.k.paul

Reputation: 7291

PetaPOCO with MS Access database

I'm trying to test PetaPOCO with MS Access database.

Connection string in web.config

<add name="ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Data.mdb; Persist Security Info=False" providerName="System.Data.Oledb" />

Accessing MS Access database-

var db = new PetaPoco.Database("ConString"); //throws exception here
var rows = db.Query<Model>("SELECT * FROM Table");

Exception thrown-

"Could not match `System.Data.Oledb` to a provider.Parameter name: providerName"

Is there any way to do it? If yes, how?

Upvotes: 2

Views: 1464

Answers (3)

Plebsori
Plebsori

Reputation: 1085

Starting with PetaPoco version 5.1.127 or later, MS Access support is backed in and no custom DB provider is required.

Sample config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <clear />
    <add name="msaccess" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Databases\MSAccess\petapoco.accdb" providerName="OleDb"/>
  </connectionStrings>
</configuration>

Fluent configuration

var builder = DatabaseConfiguration.Build().UsingConnectionName("MyConnection");

var db = builder.Create();

Constructor configuration

var db = new Database("MyConnection");

Upvotes: 2

Plebsori
Plebsori

Reputation: 1085

As stated by their documentation "Works with SQL Server, SQL Server CE, SQLite, MySQL, MariaDB, and PostgreSQL. (Oracle supported but does not have integration tests).", it doesn't support MS Access

To use it, you would need to write your own provider. Samples of providers can be found here

Upvotes: 1

Jens Meinecke
Jens Meinecke

Reputation: 2940

I think what you really want is this

using System.Configuration;

and

var db = new PetaPoco.Database(ConfigurationManager.AppSettings["ConString"]); 

Upvotes: 0

Related Questions