public void Commit(Enlistment enlistment)
        {
            if (_transaction != null && !_transaction.IsUpdated)
            {
                _transaction.Commit();
                _transaction = null;

                if (Completed != null)
                {
                    Completed(this, new EventArgs());
                }

                if (_connection != null)
                {
                    if (!_connection.Options.Pooling && (_connection.OwningConnection == null || _connection.OwningConnection.IsClosed))
                    {
                        _connection.Disconnect();
                    }
                }
                _connection        = null;
                _systemTransaction = null;

                // Declare done on the enlistment
                enlistment.Done();
            }
        }
        public void Commit(Enlistment enlistment)
        {
            if (_transaction != null && !_transaction.IsCompleted)
            {
                _transaction.Commit();
                _transaction = null;

                Completed?.Invoke(this, new EventArgs());

                if (_connection != null)
                {
                    if (!_connection.Options.Pooling && (_connection.OwningConnection == null || _connection.OwningConnection.IsClosed))
                    {
                        _connection.Disconnect(new AsyncWrappingCommonArgs(false)).GetAwaiter().GetResult();
                    }
                }
                _connection        = null;
                _systemTransaction = null;

                // Declare done on the enlistment
                enlistment.Done();
            }
        }
Ejemplo n.º 3
0
        public static void CreateDatabase(string connectionString, int pageSize = 4096, bool forcedWrites = true, bool overwrite = false)
        {
            var options = new ConnectionString(connectionString);

            options.Validate();

            try
            {
                var db = new FbConnectionInternal(options);
                try
                {
                    db.CreateDatabase(pageSize, forcedWrites, overwrite);
                }
                finally
                {
                    db.Disconnect();
                }
            }
            catch (IscException ex)
            {
                throw FbException.Create(ex);
            }
        }
Ejemplo n.º 4
0
        public static void DropDatabase(string connectionString)
        {
            var options = new ConnectionString(connectionString);

            options.Validate();

            try
            {
                var db = new FbConnectionInternal(options);
                try
                {
                    db.DropDatabase();
                }
                finally
                {
                    db.Disconnect();
                }
            }
            catch (IscException ex)
            {
                throw FbException.Create(ex);
            }
        }
Ejemplo n.º 5
0
        static async Task DropDatabaseImpl(string connectionString, AsyncWrappingCommonArgs async)
        {
            var options = new ConnectionString(connectionString);

            options.Validate();

            try
            {
                var db = new FbConnectionInternal(options);
                try
                {
                    await db.DropDatabase(async).ConfigureAwait(false);
                }
                finally
                {
                    await db.Disconnect(async).ConfigureAwait(false);
                }
            }
            catch (IscException ex)
            {
                throw FbException.Create(ex);
            }
        }
Ejemplo n.º 6
0
        private static async Task CreateDatabaseImpl(string connectionString, int pageSize, bool forcedWrites, bool overwrite, AsyncWrappingCommonArgs async)
        {
            var options = new ConnectionString(connectionString);

            options.Validate();

            try
            {
                var db = new FbConnectionInternal(options);
                try
                {
                    await db.CreateDatabase(pageSize, forcedWrites, overwrite, async).ConfigureAwait(false);
                }
                finally
                {
                    await db.Disconnect(async).ConfigureAwait(false);
                }
            }
            catch (IscException ex)
            {
                throw FbException.Create(ex);
            }
        }
Ejemplo n.º 7
0
 public void Dispose()
 {
     _connection.Disconnect();
 }
Ejemplo n.º 8
0
        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);

                var createdNew = default(bool);
                if (_options.Pooling)
                {
                    _innerConnection = FbConnectionPoolManager.Instance.Get(_options, out createdNew);
                }
                else
                {
                    _innerConnection = new FbConnectionInternal(_options);
                    createdNew       = true;
                }
                if (createdNew)
                {
                    try
                    {
                        _innerConnection.Connect();
                    }
                    catch (OperationCanceledException ex)
                    {
                        //cancellationToken.ThrowIfCancellationRequested();
                        throw new TimeoutException("Timeout while connecting.", ex);
                    }
                    catch
                    {
                        if (_options.Pooling)
                        {
                            FbConnectionPoolManager.Instance.Release(_innerConnection, false);
                        }
                        throw;
                    }
                }
                _innerConnection.SetOwningConnection(this);

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

                        if (_options.Pooling)
                        {
                            FbConnectionPoolManager.Instance.Release(_innerConnection, true);
                        }
                        else
                        {
                            _innerConnection.Disconnect();
                            _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 FbException.Create(ex);
            }
            catch
            {
                OnStateChange(_state, ConnectionState.Closed);
                throw;
            }
        }
 private Task DisposeImpl(AsyncWrappingCommonArgs async)
 {
     return(_connection.Disconnect(async));
 }
        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;
            }
        }