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(); } } _connection = null; _systemTransaction = null; // Declare done on the enlistment enlistment.Done(); } }
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); } }
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); } }
public void Dispose() { _connection.Disconnect(); }
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; } }