private void Expire(FbConnectionInternal connection)
 {
     try
     {
         connection.Dispose();
         connection = null;
     }
     catch (Exception)
     {
         // Do not raise an exception as the connection could be invalid due to several reasons
         // ( network problems, server shutdown, ... )
     }
 }
Ejemplo n.º 2
0
        public override void Open()
        {
            lock (this)
            {
                if (string.IsNullOrEmpty(_connectionString))
                {
                    throw new InvalidOperationException("Connection String is not initialized.");
                }
                if (!IsClosed && _state != ConnectionState.Connecting)
                {
                    throw new InvalidOperationException("Connection already Open.");
                }
#if !NETCORE10
                if (_options.Enlist && System.Transactions.Transaction.Current == null)
                {
                    throw new InvalidOperationException("There is no active TransactionScope to enlist transactions.");
                }
#endif

                try
                {
                    OnStateChange(_state, ConnectionState.Connecting);

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

#if !NETCORE10
                    try
                    {
                        _innerConnection.EnlistTransaction(System.Transactions.Transaction.Current);
                    }
                    catch
                    {
                        // if enlistment fails clean up innerConnection
                        _innerConnection.DisposeTransaction();

                        if (_options.Pooling)
                        {
                            // Send connection return back to the Pool
                            FbConnectionPoolManager.Instance.Release(_innerConnection);
                        }
                        else
                        {
                            _innerConnection.Dispose();
                            _innerConnection = null;
                        }

                        throw;
                    }
#endif

                    // Bind	Warning	messages event
                    _innerConnection.Database.WarningMessage = new WarningMessageCallback(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 void Expire(FbConnectionInternal connection)
		{
			try
			{
				connection.Dispose();
                connection = null;
			}
			catch
			{
                // Do not raise an exception as the connection could be invalid due to several reasons
                // ( network problems, server shutdown, ... )
			}
		}
Ejemplo n.º 4
0
 public void Dispose()
 {
     _connection.Dispose();
 }
        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;
            }
        }
			public void ReleaseConnection(FbConnectionInternal connection)
			{
				lock (_syncRoot)
				{
					CheckDisposedImpl();

					var removed = _busy.Remove(connection);
					if (removed && _available.Count < _connectionString.MaxPoolSize)
					{
						_available.Push(new Item(DateTimeOffset.UtcNow, connection));
					}
                    else
                    {
                        connection.Dispose();
                    }
                }
			}