Archive for August 2012

Errors when using PetaPoco with MySql drivers

August 24, 2012

While using PetaPoco with MySql I was getting these obscure errors that were causing the Micro ORM not to function. The reason was that PetaPoco is not built to natively use MySql and therefore requires additional configuration in order to work.

Typical errors that you will see are :

    Keyword not supported: ‘port’.

    Unable to find the requested .Net Framework Data Provider. It may not be installed.

Completely useless in diagnosing the actual issue… well at least I found them useless. Smile

The solution I discovered was to add three items of configuration. Firstly add “providerName” to your connection string:

<add name="TestConnection" connectionString="Server=localhost;Port=3306;Database=sakila;User ID=xxx;Password=xxx;" providerName="MySql.Data.MySqlClient" />

Secondly add a section to your configuration file (app.config or web.config):

      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/>

Lastly add a reference to MySql.Data.Entities. You can get it here on Nuget.
That’s it! PetaPoco will now happily use MySql!