I tried to access a PostgreSQL database using PetaPoco but i got this exception : "Could not load the PostgreSQLDatabaseProvider DbProviderFactory."
The problem is linked to the fact that the database access is done in a different assembly than my web application.
So, to avoid the exception, I currently need to load npgsql's database provider not only in my DAL assembly but in my web application too.
How can I avoid that ?
Code in a DAL assembly :
try
{
using (Database db = new PetaPoco.Database("MyDb"))
{
// things ...
return true;
}
}
catch (Exception ex)
{
// TODO: log exception
return false;
}
web.config of the web application :
<connectionStrings>
<add name="MyDb" connectionString="Server=127.0.0.1;Port=5432;Database=mydatabase;User Id=the_user;Password=the_password;" providerName="Npgsql" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server"
type="Npgsql.NpgsqlFactory, Npgsql, Version=3.0.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"/>
</DbProviderFactories>
</system.data>