Exemple #1
0
    public override void Close()
    {
        if (!IsClosed && _innerConnection != null)
        {
            try
            {
                _innerConnection.CloseEventManager();

                if (_innerConnection.Database != null)
                {
                    _innerConnection.Database.WarningMessage = null;
                }

                _innerConnection.DisposeTransaction();

                _innerConnection.ReleasePreparedCommands();

                if (_options.Pooling)
                {
                    if (_innerConnection.CancelDisabled)
                    {
                        _innerConnection.EnableCancel();
                    }

                    var broken = _innerConnection.Database.ConnectionBroken;
                    FbConnectionPoolManager.Instance.Release(_innerConnection, !broken);
                    if (broken)
                    {
                        DisconnectEnlistedHelper();
                    }
                }
                else
                {
                    DisconnectEnlistedHelper();
                }
            }
            catch
            { }
            finally
            {
                OnStateChange(_state, ConnectionState.Closed);
            }
        }

        void DisconnectEnlistedHelper()
        {
            if (!_innerConnection.IsEnlisted)
            {
                _innerConnection.Disconnect();
            }
            _innerConnection = null;
        }
    }