public override void ChangeDatabase(string db) { CheckClosed(); if (string.IsNullOrEmpty(db)) { throw new InvalidOperationException("Database name is not valid."); } var oldConnectionString = _connectionString; try { var csb = new FbConnectionStringBuilder(_connectionString); /* Close current connection */ Close(); /* Set up the new Database */ csb.Database = db; ConnectionString = csb.ToString(); /* Open new connection */ Open(); } catch (IscException ex) { ConnectionString = oldConnectionString; throw FbException.Create(ex); } }
public void Connect() { if (Charset.GetCharset(_options.Charset) == null) { throw FbException.Create("Invalid character set specified"); } try { _db = ClientFactory.CreateDatabase(_options); _db.Charset = Charset.GetCharset(_options.Charset); _db.Dialect = _options.Dialect; _db.PacketSize = _options.PacketSize; var dpb = BuildDpb(_db, _options); if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { _db.AttachWithTrustedAuth(dpb, _options.Database, _options.CryptKey); } else { _db.Attach(dpb, _options.Database, _options.CryptKey); } } catch (IscException ex) { throw FbException.Create(ex); } }
private async Task ChangeDatabaseImpl(string db, AsyncWrappingCommonArgs async) { CheckClosed(); if (string.IsNullOrEmpty(db)) { throw new InvalidOperationException("Database name is not valid."); } var oldConnectionString = _connectionString; try { var csb = new FbConnectionStringBuilder(_connectionString); /* Close current connection */ await CloseImpl(async).ConfigureAwait(false); /* Set up the new Database */ csb.Database = db; ConnectionString = csb.ToString(); /* Open new connection */ await OpenImpl(async).ConfigureAwait(false); } catch (IscException ex) { ConnectionString = oldConnectionString; throw FbException.Create(ex); } }
protected override void Dispose(bool disposing) { if (!_disposed) { _disposed = true; if (_transaction != null) { if (!_isCompleted) { try { _transaction.Dispose2(); } catch (IscException ex) { throw FbException.Create(ex); } } } _connection = null; _transaction = null; _isCompleted = true; } base.Dispose(disposing); }
public override async Task ChangeDatabaseAsync(string db, CancellationToken cancellationToken = default) #endif { CheckClosed(); if (string.IsNullOrEmpty(db)) { throw new InvalidOperationException("Database name is not valid."); } var oldConnectionString = _connectionString; try { var csb = new FbConnectionStringBuilder(_connectionString); /* Close current connection */ await CloseAsync().ConfigureAwait(false); /* Set up the new Database */ csb.Database = db; ConnectionString = csb.ToString(); /* Open new connection */ await OpenAsync(cancellationToken).ConfigureAwait(false); } catch (IscException ex) { ConnectionString = oldConnectionString; throw FbException.Create(ex); } }
public async Task ConnectAsync(CancellationToken cancellationToken = default) { if (Charset.GetCharset(_options.Charset) == null) { throw FbException.Create("Invalid character set specified"); } try { _db = await ClientFactory.CreateDatabaseAsync(_options, cancellationToken).ConfigureAwait(false); _db.Charset = Charset.GetCharset(_options.Charset); _db.Dialect = _options.Dialect; _db.PacketSize = _options.PacketSize; var dpb = BuildDpb(_db, _options); if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { await _db.AttachWithTrustedAuthAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } else { await _db.AttachAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } } catch (IscException ex) { throw FbException.Create(ex); } }
public override async ValueTask DisposeAsync() { if (!_disposed) { _disposed = true; if (_transaction != null) { if (!_isCompleted) { try { await _transaction.Dispose2Async(CancellationToken.None).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } } } _connection = null; _transaction = null; _isCompleted = true; } await base.DisposeAsync().ConfigureAwait(false); }
public async Task Connect(AsyncWrappingCommonArgs async) { if (Charset.GetCharset(_options.Charset) == null) { throw FbException.Create("Invalid character set specified"); } try { _db = await ClientFactory.CreateDatabase(_options, async).ConfigureAwait(false); _db.Charset = Charset.GetCharset(_options.Charset); _db.Dialect = _options.Dialect; _db.PacketSize = _options.PacketSize; var dpb = BuildDpb(_db, _options); if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { await _db.AttachWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey, async).ConfigureAwait(false); } else { await _db.Attach(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey, async).ConfigureAwait(false); } } catch (IscException ex) { throw FbException.Create(ex); } }
private async Task CancelEventsImpl(AsyncWrappingCommonArgs async) { try { await _revent.CancelEvents(async).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
public void CancelEvents() { try { _revent.CancelEvents(); } catch (IscException ex) { throw FbException.Create(ex); } }
public async Task CancelEventsAsync(CancellationToken cancellationToken = default) { try { await _revent.CancelEventsAsync(cancellationToken).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
private static T CheckedGetValue <T>(Func <AsyncWrappingCommonArgs, ValueTask <T> > getter) { try { return(getter(new AsyncWrappingCommonArgs(false)).GetAwaiter().GetResult()); } catch (IscException ex) { throw FbException.Create(ex); } }
private static T CheckedGetValue2 <T>(Func <T> getter) { try { return(getter()); } catch (IscException ex) { throw FbException.Create(ex); } }
public async Task RollbackRetainingAsync(CancellationToken cancellationToken = default) { EnsureCompleted(); try { await _transaction.RollbackRetainingAsync(cancellationToken).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
public void RollbackRetaining() { EnsureCompleted(); try { _transaction.RollbackRetaining(); } catch (IscException ex) { throw FbException.Create(ex); } }
private async Task RollbackRetainingImpl(AsyncWrappingCommonArgs async) { EnsureCompleted(); try { await _transaction.RollbackRetaining(async).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
public override void Rollback() { EnsureCompleted(); try { _transaction.Rollback(); CompleteTransaction(); } catch (IscException ex) { throw FbException.Create(ex); } }
internal async Task RollbackImpl(AsyncWrappingCommonArgs async) { EnsureCompleted(); try { await _transaction.Rollback(async).ConfigureAwait(false); await CompleteTransaction(async).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
public override async Task RollbackAsync(CancellationToken cancellationToken = default) #endif { EnsureCompleted(); try { await _transaction.RollbackAsync(cancellationToken).ConfigureAwait(false); await CompleteTransactionAsync(cancellationToken).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
public async Task QueueEventsAsync(ICollection <string> events, CancellationToken cancellationToken = default) { if (_revent == null) { throw new InvalidOperationException($"{nameof(FbRemoteEvent)} must be opened."); } try { await _revent.QueueEventsAsync(events, cancellationToken).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
private async Task QueueEventsImpl(ICollection <string> events, AsyncWrappingCommonArgs async) { if (_revent == null) { throw new InvalidOperationException($"{nameof(FbRemoteEvent)} must be opened."); } try { await _revent.QueueEvents(events, async).ConfigureAwait(false); } catch (IscException ex) { throw FbException.Create(ex); } }
public void QueueEvents(ICollection <string> events) { if (_revent == null) { throw new InvalidOperationException($"{nameof(FbRemoteEvent)} must be opened."); } try { _revent.QueueEvents(events); } catch (IscException ex) { throw FbException.Create(ex); } }
private async Task RollbackImpl(string savePointName, AsyncWrappingCommonArgs async) { EnsureSavePointName(savePointName); EnsureCompleted(); try { var command = new FbCommand($"ROLLBACK WORK TO SAVEPOINT {savePointName}", _connection, this); #if NET48 || NETSTANDARD2_0 using (command) #else await using (command.ConfigureAwait(false)) #endif { await async.AsyncSyncCall(command.ExecuteNonQueryAsync, command.ExecuteNonQuery).ConfigureAwait(false); } } catch (IscException ex) { throw FbException.Create(ex); } }
internal static Exception Create(string message, Exception innerException) { message ??= innerException?.Message; if (innerException is IscException iscException) { if (iscException.ErrorCode == IscCodes.isc_cancelled) { return(new OperationCanceledException(message, innerException)); } else { var result = new FbException(message, innerException); result.ProcessIscExceptionErrors(iscException); return(result); } } else { return(new FbException(message, innerException)); } }
public FbTransaction BeginTransaction(FbTransactionOptions options, string transactionName) { EnsureActiveTransaction(); try { _activeTransaction = new FbTransaction(_owningConnection, IsolationLevel.Unspecified); _activeTransaction.BeginTransaction(options); if (transactionName != null) { _activeTransaction.Save(transactionName); } } catch (IscException ex) { DisposeTransaction(); throw FbException.Create(ex); } return(_activeTransaction); }
public override void Rollback(string savePointName) #endif { EnsureSavePointName(savePointName); EnsureCompleted(); try { var command = new FbCommand($"ROLLBACK WORK TO SAVEPOINT {savePointName}", _connection, this); #if NET48 || NETSTANDARD2_0 using (command) #else using (command) #endif { command.ExecuteNonQuery(); } } catch (IscException ex) { throw FbException.Create(ex); } }
public override async Task RollbackAsync(string savePointName, CancellationToken cancellationToken = default) #endif { EnsureSavePointName(savePointName); EnsureCompleted(); try { var command = new FbCommand($"ROLLBACK WORK TO SAVEPOINT {savePointName}", _connection, this); #if NET48 || NETSTANDARD2_0 using (command) #else await using (command.ConfigureAwait(false)) #endif { await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); } } catch (IscException ex) { throw FbException.Create(ex); } }
internal async Task <int> ExecuteNonQueryImpl(AsyncWrappingCommonArgs async) { CheckCommand(); try { using (async.EnterExplicitCancel(Cancel)) { await ExecuteCommand(CommandBehavior.Default, false, async).ConfigureAwait(false); if (_statement.StatementType == DbStatementType.StoredProcedure) { await SetOutputParameters(async).ConfigureAwait(false); } await CommitImplicitTransaction(async).ConfigureAwait(false); } } catch (IscException ex) { await RollbackImplicitTransaction(async).ConfigureAwait(false); throw FbException.Create(ex); } catch { await RollbackImplicitTransaction(async).ConfigureAwait(false); throw; } return(_statement.StatementType switch { DbStatementType.Insert => RecordsAffected, DbStatementType.Update => RecordsAffected, DbStatementType.Delete => RecordsAffected, _ => - 1, });
public async Task <FbTransaction> BeginTransactionAsync(FbTransactionOptions options, string transactionName, CancellationToken cancellationToken = default) { EnsureActiveTransaction(); try { _activeTransaction = new FbTransaction(_owningConnection, IsolationLevel.Unspecified); await _activeTransaction.BeginTransactionAsync(options, cancellationToken).ConfigureAwait(false); if (transactionName != null) { _activeTransaction.Save(transactionName); } } catch (IscException ex) { await DisposeTransactionAsync(cancellationToken).ConfigureAwait(false); throw FbException.Create(ex); } return(_activeTransaction); }
public static async Task CreateDatabaseAsync(string connectionString, int pageSize = 4096, bool forcedWrites = true, bool overwrite = false, CancellationToken cancellationToken = default) { var options = new ConnectionString(connectionString); options.Validate(); try { var db = new FbConnectionInternal(options); try { await db.CreateDatabaseAsync(pageSize, forcedWrites, overwrite, cancellationToken).ConfigureAwait(false); } finally { await db.DisconnectAsync(cancellationToken).ConfigureAwait(false); } } catch (IscException ex) { throw FbException.Create(ex); } }
private void WriteToEventLog(FbException e, string action) { EventLog log = new EventLog(); log.Source = eventSource; log.Log = eventLog; StringBuilder sb = new StringBuilder(50); sb.AppendFormat("An exception occurred. Please check the Event Log.{0}", Environment.NewLine); sb.AppendLine(); sb.AppendFormat("Action: {0}{1}", action, Environment.NewLine); sb.AppendLine(); sb.AppendFormat("Exception: {0}{1}", e.ToString(), Environment.NewLine); log.WriteEntry(sb.ToString()); }