Ejemplo n.º 1
0
        public override void EnlistTransaction(System.Transactions.Transaction transaction)
        {
            CheckClosed();

            if (transaction == null)
            {
                return;
            }

            _innerConnection.EnlistTransaction(transaction);
        }
Ejemplo n.º 2
0
        public override void EnlistTransaction(System.Transactions.Transaction transaction)
        {
            CheckClosed();

            _innerConnection.EnlistTransaction(transaction);
        }
        public override void Open()
        {
            if (string.IsNullOrEmpty(_connectionString))
            {
                throw new InvalidOperationException("Connection String is not initialized.");
            }
            if (!IsClosed && _state != ConnectionState.Connecting)
            {
                throw new InvalidOperationException("Connection already Open.");
            }

            try
            {
                OnStateChange(_state, ConnectionState.Connecting);

                if (_options.Pooling)
                {
                    _innerConnection = FbConnectionPoolManager.Instance.Get(_options, this);
                }
                else
                {
                    _innerConnection = new FbConnectionInternal(_options);
                    _innerConnection.SetOwningConnection(this);
                    _innerConnection.Connect();
                }

                if (_options.Enlist)
                {
                    try
                    {
                        var transaction = System.Transactions.Transaction.Current;
                        if (transaction != null)
                        {
                            _innerConnection.EnlistTransaction(transaction);
                        }
                    }
                    catch
                    {
                        // if enlistment fails clean up innerConnection
                        _innerConnection.DisposeTransaction();

                        if (_options.Pooling)
                        {
                            FbConnectionPoolManager.Instance.Release(_innerConnection, true);
                        }
                        else
                        {
                            _innerConnection.Dispose();
                            _innerConnection = null;
                        }

                        throw;
                    }
                }

                // Bind	Warning	messages event
                _innerConnection.Database.WarningMessage = OnWarningMessage;

                // Update the connection state
                OnStateChange(_state, ConnectionState.Open);
            }
            catch (IscException ex)
            {
                OnStateChange(_state, ConnectionState.Closed);
                throw new FbException(ex.Message, ex);
            }
            catch
            {
                OnStateChange(_state, ConnectionState.Closed);
                throw;
            }
        }
        private async Task OpenImpl(AsyncWrappingCommonArgs async)
        {
            if (string.IsNullOrEmpty(_connectionString))
            {
                throw new InvalidOperationException("Connection String is not initialized.");
            }
            if (!IsClosed && _state != ConnectionState.Connecting)
            {
                throw new InvalidOperationException("Connection already Open.");
            }

            try
            {
                OnStateChange(_state, ConnectionState.Connecting);

                var createdNew = default(bool);
                if (_options.Pooling)
                {
                    _innerConnection = FbConnectionPoolManager.Instance.Get(_options, out createdNew);
                }
                else
                {
                    _innerConnection = new FbConnectionInternal(_options);
                    createdNew       = true;
                }
                if (createdNew)
                {
                    try
                    {
                        await _innerConnection.Connect(async).ConfigureAwait(false);
                    }
                    catch
                    {
                        if (_options.Pooling)
                        {
                            FbConnectionPoolManager.Instance.Release(_innerConnection, false);
                        }
                        throw;
                    }
                }
                _innerConnection.SetOwningConnection(this);

                if (_options.Enlist)
                {
                    try
                    {
                        var transaction = System.Transactions.Transaction.Current;
                        if (transaction != null)
                        {
                            _innerConnection.EnlistTransaction(transaction);
                        }
                    }
                    catch
                    {
                        // if enlistment fails clean up innerConnection
                        await _innerConnection.DisposeTransaction(async).ConfigureAwait(false);

                        if (_options.Pooling)
                        {
                            FbConnectionPoolManager.Instance.Release(_innerConnection, true);
                        }
                        else
                        {
                            await _innerConnection.Disconnect(async).ConfigureAwait(false);

                            _innerConnection = null;
                        }

                        throw;
                    }
                }

                // Bind	Warning	messages event
                _innerConnection.Database.WarningMessage = OnWarningMessage;

                // Update the connection state
                OnStateChange(_state, ConnectionState.Open);
            }
            catch (IscException ex)
            {
                OnStateChange(_state, ConnectionState.Closed);
                throw new FbException(ex.Message, ex);
            }
            catch
            {
                OnStateChange(_state, ConnectionState.Closed);
                throw;
            }
        }