void CloseImpl()
        {
            if (_internalConnection != null)
            {
                if (_internalConnection.transaction != null)
                    _internalConnection.transaction.Rollback();
                if (_pooled)
                {
                    _internalConnection.CloseOpenItems();
                    ConnectionPoolManager.Instance.Release(_internalConnection);
                }
                else
                    _internalConnection.Close();
                _pooled = false;
                _internalConnection = null;
            }

            OnStateChange(_state, ConnectionState.Closed);
        }
        public override void Open()
        {
            CheckDisposed();

            if (_state != ConnectionState.Closed)
                throw new InvalidOperationException();

            OnStateChange(_state, ConnectionState.Connecting);

            if (_parsedConnectionString.PoolingOrDefault)
            {
                _pooled = true;
                try
                {
                    _internalConnection = ConnectionPoolManager.Instance.Get(_connectionString);
                }
                catch
                {
                    CloseImpl();

                    throw;
                }
            }
            else
            {
                _internalConnection = new NuoDbConnectionInternal(_connectionString);
                try
                {
                    _internalConnection.Open();
                }
                catch
                {
                    CloseImpl();

                    throw;
                }
            }
            _internalConnection.Owner = this;

            OnStateChange(_state, ConnectionState.Open);
        }