NpgSQL 3 Code First Connection String

entity-framework entity-framework-6 npgsql

Question

I am trying to setup a project with EF6 and NpgSQL 3.x

I took the following steps:

  1. Used Nuget to install Entity Framework 6
  2. List item
  3. Add connections string to .config file using syntax described here: http://www.npgsql.org/doc/connection-string-parameters.html

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.

1
0
3/6/2016 1:13:39 AM

Popular Answer

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>
0
9/27/2016 10:25:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow