Jason Ellison
Jason Ellison

Reputation: 51

Npgsql is not able to talk to PostgreSQL after upgrading from postgresql 9.x to postgresql 13

After upgrading a PostgreSQL server to version 13, Npgsql is no longer able to connect. This is a .NET application. Communications was verified via the command line psql command. I can not seem to get any useful errors from the developer to further investigate. I did have the developer upgrade Npgsql to version 5.0.1.1, to no avail.

Any tips on debugging further would be greatly appreciated!

ERROR 2020-12-16 16:02:44,499 333535ms Archive                rieveUnlimitedData - Npgsql.NpgsqlException (0x80004005): Exception while reading from stream ---> System.TimeoutException: Timeout during reading attempt
   at Npgsql.NpgsqlConnector.<<ReadMessage>g__ReadMessageLong|194_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDataReader.<>c__DisplayClass41_0.<<ReadMessage>g__ReadMessageSequential|0>d.MoveNext()

Test with psql:

C:\Program Files\PostgreSQL\13\bin>psql.exe -h XXX.XXXX.com -U postgres -d ais
Password for user postgres:
psql (13.1, server 13.0)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

ais=# \d
                 List of relations
  Schema  |       Name        |   Type   |  Owner
----------+-------------------+----------+----------
 public   | geography_columns | view     | postgres

This is all the code I could get:

<add name="rawDB"
     connectionString="server=host05.xxxxxx.local;port=5432;database=ais;uid=xxxxxxxxxxxx;password=xxxxxxxxxxx;timeout=30;commandtimeout=30" providerName="Npgsql"
/>
var connection = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["rawDB"].ConnectionString);
connection.Open();
var cmdSel = new NpgsqlCommand(queryText, connection);

Upvotes: 1

Views: 6900

Answers (1)

Jason Ellison
Jason Ellison

Reputation: 51

commandtimeout=0 solved the issue. I suspect the increased time for authentication (SASL exchange) cause the issue to occur after changing from PostgreSQL v9.x to PostgreSQL v13.x.

Upvotes: 2

Related Questions