Exemple #1
0
        /// <summary>
        /// Cancels and terminates an ongoing operation. Any data already written will be discarded.
        /// </summary>
        public void Cancel()
        {
            CheckDisposed();

            if (CanWrite)
            {
                _isDisposed = true;
                _writeBuf.EndCopyMode();
                _writeBuf.Clear();
                _connector.SendMessage(new CopyFailMessage());
                try
                {
                    var msg = _connector.ReadMessage();
                    // 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();
            }
        }
Exemple #2
0
 /// <summary>
 /// Cancels and terminates an ongoing import. Any data already written will be discarded.
 /// </summary>
 public void Cancel()
 {
     _isDisposed = true;
     _buf.EndCopyMode();
     _connector.SendMessage(new CopyFailMessage());
     try {
         var msg = _connector.ReadMessage();
         // 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")
         {
             throw;
         }
     }
     // Note that the exception has already ended the user action for us
     Cleanup();
 }