5
I am trying to connect the EF in Postgresql. You are presenting the following message:
An unhandled Exception of type 'System.Configuration.Configurationerrorsexception' occurred in System.Configuration.dll
Additional information: An error occurred while creating the system.data configuration section: The 'Invariantname' column is restricted to contain exclusive values. Npgsql value already exists.
My Class Context:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using Npgsql;
namespace TesteEnti
{
class testeBD: DbContext
{
public testeBD()
: base("TesteDB")
{
}
public DbSet<Usuario> Usuario { get; set; }
}
}
My APP Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name ="TesteDB" connectionString="server=localhost;user id=postgres;password=flavio123;database=testedb" providerName="Npgsql"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
</configuration>
I have the packages installed, EF and NPGSQL EF.
What I could do to solve this problem?
Take the entire dbProvidersFactory tag from the web.config and test
– Jéf Bueno