简体   繁体   中英

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server, pgsql

I am using Dapper to connect to pgsql database. The below code was working few days back. But don't know why its not working now. The same credentials are working with pgadmin3 but not with the c# code. here is the controller method, for simplicity I wrote all db code in Get method.

the below code was

public IEnumerable<Item> Get()
    {
        string connString = "Server=192.168.1.11;Database=db_alpha1;Uid=postgres;Pwd=xxxxxx";

        using (IDbConnection db = new SqlConnection(connString))
        {
            db.Open();

            return db.Query<Item>("Select * From items").ToList();
        }
    }

Here is the error on line db.Open(); :

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)

Also, I already configured pg_hba.conf file, added my system ip address.

Thanks to @Steve. The issue has resolved, it was a silly mistake, I replaced SqlConnection with NpgsqlConnection, and added npgsql package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM