npgsql: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

I am receiving this error when trying to make a connection.

{ “message”: “Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.”, “stackTrace”: " at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)\r\n at Npgsql.NpgsqlBuffer.Ensure(Int32 count)\r\n at Npgsql.NpgsqlConnector.DoReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage, Boolean isPrependedMessage)\r\n at Npgsql.NpgsqlConnector.ReadSingleMessageWithPrepended(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage)\r\n at Npgsql.NpgsqlConnector.ReadSingleMessage(DataRowLoadingMode dataRowLoadingMode)\r\n at Npgsql.NpgsqlConnector.HandleAuthentication(NpgsqlTimeout timeout)\r\n at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)\r\n at Npgsql.NpgsqlConnector.Open()\r\n at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection)\r\n at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection connection)\r\n at Npgsql.NpgsqlConnection.OpenInternal(NpgsqlTimeout timeout)\r\n at Npgsql.NpgsqlConnection.Open()\r\n at AACEI_Info_2.Controllers.Api.VersionController.Get(Nullable`1 id)" }

Here is my connection information

        using (var conn = new NpgsqlConnection("Host=ccureatl;username=xxx;password=xxx;database=xx;port=2500"))
        {
            try
            {
                conn.Open();
            }
            catch (NpgsqlException npex)
            {

                _logger.LogError(npex.Message);
            }
            catch(Exception ex)
            {
                _logger.LogError(ex.Message);
                return Json(new { Message = ex.Message, StackTrace = ex.StackTrace });
            }
            finally
            {
                if (conn.State==System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }

        }

Here are the packages I am using “EntityFramework7.Npgsql”: “3.1.0-rc1-3”, “EntityFramework7.Npgsql.Design”: “3.1.0-rc1-3”,

Not sure what I am doing incorrectly.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (10 by maintainers)

Most upvoted comments

Try use Pooling=False in connectionString. Same issue https://github.com/npgsql/npgsql/issues/933