3
votes

I'm using Npgsql 3.1.7 since yesterday when I have updated it to 3.1.8 via Nuget but I get the same exception.

I'm connecting to a remote Windows server 2012 and Postgresql 9.5 also tried Postgresql 9.4 on Debian 8 with the same behavior.

What I'm trying to do is to select data via COPY(select..) command using Npgsql BeginBinaryExport but after some seconds the exception is thrown. This happens every run. I tried to apply Pooling=false,Keepalive=10, commandtimeout=0 to the connection string without success.

I'm getting:

Exception while reading from stream Unable to read data from the transport connection: Unable to establish connection. Wrong answer from the connected part after a timeout interval or missing response.

This last part is in italian, I tried to translate it, I hope you can understand it anyway.

Here the StackTrace:

Exception thrown: 'Npgsql.NpgsqlException' in Npgsql.dll in Npgsql.ReadBuffer.Ensure(Int32 count, Boolean dontBreakOnTimeouts) in Npgsql.NpgsqlConnector.DoReadMessage(DataRowLoadingMode dataRowLoadingMode, Boolean isPrependedMessage) in Npgsql.NpgsqlConnector.ReadMessageWithPrepended(DataRowLoadingMode dataRowLoadingMode) in Npgsql.NpgsqlConnector.ReadExpectingT in Npgsql.NpgsqlBinaryExporter..ctor(NpgsqlConnector connector, String copyToCommand) in Npgsql.NpgsqlConnection.BeginBinaryExport(String copyToCommand)

I tried to change the command from COPY(select ...) to a simple select using NpgsqlCommand and it works, but if I remove Pooling=false,Keepalive=10, commandtimeout=0 from the connection string the exception returns.

EDIT: The code I'm using is:

using (var reader = connection.BeginBinaryExport("COPY (select * from \"DTC_Det\") TO STDOUT (FORMAT BINARY)")){ ... }

any idea?

1
Can you post the relevant code you are using? What's your COPY statement, are you specifying TO STDOUT and (FORMAT BINARY), like this? Conn.BeginBinaryExport("COPY data (field_text, field_int2) TO STDOUT (FORMAT BINARY)")) - yscik
code added to the question. - Gappa
Is DTC_Det a view? As far as I know, there is no way to set a timeout property on a Begin Text/Binary Import/Export, but if you are doing a raw import/export of a table, it should hardly be necessary. If this is a view, then that's a horse of a different color - Hambone
thanks for the answer. DTC_Det is not a view, it is a normal table - Gappa

1 Answers

0
votes

string connectionString = Host=servername;Username=postgres;Password=password;Database=postgres;port=1234;Timeout=50;

It will work in c#.