Exception while reading from stream error while connecting to npgsql

0

I have a c# application and postgres database. While I am trying to connect to database from app I get exception message showing Exception while reading from stream. Following is my connection code

string connectionString = "Server=127.0.0.1;Port=6000;User Id=postgres; Password=123; Database=postgres; CommandTimeout=120;";
            var connection = new Npgsql.NpgsqlConnection(connectionString);
            connection.Open();

Issue is occurring on one windows device. other devices works fine. Is there any issue in my connection string? below is the full error

Npgsql.NpgsqlException (0x80004005): Exception while reading from stream ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<g__EnsureLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlReadBuffer.cs:line 139 at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<g__EnsureLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlReadBuffer.cs:line 167 --- 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.NpgsqlConnector.<>c__DisplayClass160_0.<g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 980 --- 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.NpgsqlConnector.d__0.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.Auth.cs:line 22 --- 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.NpgsqlConnector.d__148.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 423 --- 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.ConnectorPool.d__28.MoveNext() in C:\projects\npgsql\src\Npgsql\ConnectorPool.cs:line 249 --- 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 System.Threading.Tasks.ValueTask1.get_Result() at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 297 --- 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.NpgsqlConnection.Open() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 119 at HexnodeInstaller.DBOps.WriteTable(String tableName, List1 columnNames, List`1 values) in C:\Users\ijas.m\Hexnode\hexnodeinstaller\DBOps.cs:line 144

c#
asp.net
.net
postgresql
npgsql
asked on Stack Overflow May 19, 2020 by Ijas • edited May 19, 2020 by Ijas

1 Answer

0

Please check this answer from Npgsql guys: https://github.com/npgsql/npgsql/issues/1354

Probably you can play a little with timeout config in that machine to check if it's a communication issue as it seems.

answered on Stack Overflow May 19, 2020 by Pablo CG

User contributions licensed under CC BY-SA 3.0