public void Close() { if (_isDisposed) { return; } if (_column != -1 && _column != NumColumns) { Log.Error("Binary importer closed in the middle of a row, cancelling import."); _buf.Clear(); Cancel(); return; } WriteTrailer(); _buf.Flush(); _buf.EndCopyMode(); var connector = _connector; connector.SendMessage(CopyDoneMessage.Instance); try { connector.ReadExpecting <CommandCompleteMessage>(); connector.ReadExpecting <ReadyForQueryMessage>(); } finally { Cleanup(); connector.EndUserAction(); } }
/// <summary> /// Cancels and terminates an ongoing operation. Any data already written will be discarded. /// </summary> public void Cancel() { CheckDisposed(); if (CanWrite) { _isDisposed = true; _writeBuf.Clear(); _connector.SendMessage(new CopyFailMessage()); try { var msg = _connector.ReadMessage(DataRowLoadingMode.NonSequential); // The CopyFail should immediately trigger an exception from the read above. _connector.Break(); throw new NpgsqlException("Expected ErrorResponse when cancelling COPY but got: " + msg.Code); } catch (PostgresException e) { if (e.SqlState == "57014") { return; } throw; } } else { _connector.CancelRequest(); } }