I am trying to setup a project with EF6 and NpgSQL 3.x
I took the following steps:
Used Nuget to install NpgSQL EntityFramework6 package
When I try to connect to the database I get the error:
"Keyword not supported: 'port'."
referring to the port setting in the connection string if i remove the "port" the connection fails with error:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
The error message seems like it is trying to connect using SQL server protocol not postgres. Is there any additional steps I need to take to get this setup?
Most of the .config file examples in the documentation appear outdated so I am wondering if need to manually add a setting to the config somewhere.
If anyone has this setup working could you share your .config files thanks.
You're right about : "it is trying to connect using SQL server protocol not postgres", because it's the default provider.
You have to add the Npgsql provider to the DbProviderFactories and EF providers in web.config, then link the connection string to that provider (see
providerName), so entityframe can connect to postgresql:
<system.data> <DbProviderFactories> <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" /> </DbProviderFactories> </system.data> <entityFramework> <providers> <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" /> </providers> </entityFramework> <connectionStrings> <add name="CS" connectionString="Server=127.0.0.1;Port=5432;Database=MYDB;User Id=postgres;Password=mypass" providerName="Npgsql" /> </connectionStrings>