Creating a PostgreSQL connection with Entity Framework and Npgsql. Error is failing trying to read from SQL Server

-2

Attempting to create above connection via Entity Framework config file, and upon running get the following error :

13:02:57.058 0 System.Data.SqlClient.SqlException (0x80131904): 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)

System.ComponentModel.Win32Exception (0x80004005): The network path was not found

Seems to not be identifying that it is a PostgreSQL connection that I am trying to make.

<configuration>
    <configSections>
        <section name="entityFramework" 
                 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                 requirePermission="false" />
    </configSections>
    <connectionStrings>
        <add name="Test_Track" 
             connectionString="server=localhost;user id=rouser;password=pass;Database=track;" 
             providerName="Npgsql" />
    </connectionStrings>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers> 
            <provider invariantName="Npgsql" 
                      type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
        </providers>
    </entityFramework>
    <system.data>
        <DbProviderFactories>
            <add name="Npgsql Data Provider" invariant="Npgsql" 
                 description=".Net Data Provider for PostgreSQL" 
                 type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"/>
        </DbProviderFactories>
    </system.data>
  • EF: Version 6.0
  • VS .NET Framework 4.5
  • Npgsql.2.2.7
  • Npgsql.EntityFramework.2.2.7

Any help at all would be greatly appreciated.

Cheers.

c#
postgresql
entity-framework
npgsql
asked on Stack Overflow Jun 10, 2018 by whatafarce • edited Jun 10, 2018 by marc_s

1 Answer

2

This error comes from the MS SQL Server Provider, not Npgsql.

The MSSQL Provider is trying to connect through Named Pipes which are a Windows only thing, not supported by Npgsql.

I would advise to review your configuration file and use Npgsql.NpgsqlConnectionFactory instead of SqlConnectionFactory as the link provided by magicandre1981 shows.

answered on Stack Overflow Jun 10, 2018 by Olivier MATROT

User contributions licensed under CC BY-SA 3.0