Fossmo
Fossmo

Reputation: 2892

Postgresql, Entity Framework and Mono 3

I'm trying to get EF to work with Postgresql on a Linux platform. When I try to connect to the database I end up with this error: Failed to find or load the registered .Net Framework Data Provider 'Npgsql Data Provider'. My app.config file:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <configSections>
      <section name="entityFramework"
        type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" />
    </configSections>
    <system.data>
      <DbProviderFactories>
        <remove invariant="Npgsql"></remove>
        <add name="Npgsql Data Provider" 
          invariant="Npgsql" 
          description=".Net Framework Data Provider for Postgresql Server" 
          type="Npgsql.NpgsqlFactory, Npgsql, Version=4.0.0.0, Culture=neutral" />
      </DbProviderFactories>
    </system.data>
    <connectionStrings>
      <add name="MinDatabase" connectionString="Server=localhost;Port=5432;Database=postgres;User Id=postgres;Password=;CommandTimeout=20;" 
        providerName="Npgsql Data Provider" />
    </connectionStrings>
  </configuration>

How can I make Mono load the data provider?

Upvotes: 2

Views: 1833

Answers (2)

Francisco Junior
Francisco Junior

Reputation: 2016

Where did you download Npgsql from? If you are using Npgsql from official releases, your problem is the Version attribute of the assembly. Npgsql which supports EF 4.x has version 2.0.14.3 and Npgsql which supports EF 6 has version 2.1.0. None has version 4.0.0.0.

For more info about using Npgsql with Entity Framework, check out:

How to integrate PostgreSql with EntityFramework 6.0.2?

Entity Framework 6 with Npgsql

http://fxjr.blogspot.com.br/2014/02/using-entity-framework-6-with-npgsql-210.html

I hope it helps.

Upvotes: 2

jakobandersen
jakobandersen

Reputation: 1409

The error message contains the invariant name, so its looking for something with invariant name "Npgsql Data Provider" and you specifically set the invariantName to Npgsql. So maybe try to change to use the same name all over your configuration like this:

<system.data>
  <DbProviderFactories>
    <remove invariant="Npgsql"></remove>
    <add name="Npgsql" 
      invariant="Npgsql" 
      description=".Net Framework Data Provider for Postgresql Server" 
      type="Npgsql.NpgsqlFactory, Npgsql, Version=4.0.0.0, Culture=neutral" />
  </DbProviderFactories>
</system.data>
<connectionStrings>
  <add name="MinDatabase" connectionString="Server=localhost;Port=5432;Database=postgres;User Id=postgres;Password=;CommandTimeout=20;" 
    providerName="Npgsql" />
</connectionStrings>

Hope it works

Upvotes: 3

Related Questions