private void CommitInternal() { if (null == _transaction) { return; } if (null != _nestedTransaction) { OleDbTransaction?transaction = (OleDbTransaction?)_nestedTransaction.Target; if ((null != transaction) && _nestedTransaction.IsAlive) { transaction.CommitInternal(); } _nestedTransaction = null; } OleDbHResult hr = _transaction.Commit(); if (!_transaction.MustComplete) { _transaction.Dispose(); _transaction = null; DisposeManaged(); } if (hr < 0) { // if an exception is thrown, user can try to commit their transaction again ProcessResults(hr); } }
// Connection.Close & Connection.Dispose(true) notification internal void CloseCommandFromConnection(bool canceling) { this.canceling = canceling; CloseInternal(); _trackingForClose = false; _transaction = null; //GC.SuppressFinalize(this); }
internal static OleDbTransaction?TransactionUpdate(OleDbTransaction?transaction) { if ((null != transaction) && (null == transaction._transaction)) { return(null); } return(transaction); }
internal async Task ReloadAsync(OleDbConnection connection, OleDbTransaction?transaction) { using (var cmd = new OleDbCommand("SELECT @@Options") { Connection = connection, Transaction = transaction }) m_Options = (int)(await cmd.ExecuteScalarAsync().ConfigureAwait(false) !); }
internal void Reload(OleDbConnection connection, OleDbTransaction?transaction) { using (var cmd = new OleDbCommand("SELECT @@Options") { Connection = connection, Transaction = transaction }) m_Options = (int)cmd.ExecuteScalar() !; }
internal OleDbSqlServerOpenDataSource(OleDbSqlServerDataSource dataSource, OleDbConnection connection, OleDbTransaction?transaction) : base(new SqlServerDataSourceSettings() { DefaultCommandTimeout = dataSource.DefaultCommandTimeout, StrictMode = dataSource.StrictMode, SuppressGlobalEvents = dataSource.SuppressGlobalEvents }) { if (connection == null) { throw new ArgumentNullException(nameof(connection), $"{nameof(connection)} is null."); } m_BaseDataSource = dataSource; m_Connection = connection; m_Transaction = transaction; }
internal AccessOpenDataSource(AccessDataSource dataSource, OleDbConnection connection, OleDbTransaction?transaction) : base(new AccessDataSourceSettings(dataSource)) { if (connection == null) { throw new ArgumentNullException(nameof(connection), $"{nameof(connection)} is null."); } m_BaseDataSource = dataSource; m_Connection = connection; m_Transaction = transaction; }
internal static OleDbTransaction TransactionLast(OleDbTransaction head) { if (null != head._nestedTransaction) { OleDbTransaction?current = (OleDbTransaction?)head._nestedTransaction.Target; if ((null != current) && head._nestedTransaction.IsAlive) { return(TransactionLast(current)); } } return(head); }
internal OleDbTransaction?ValidateTransaction(OleDbTransaction?transaction, string method) { if (null != this.weakTransaction) { OleDbTransaction?head = (OleDbTransaction?)this.weakTransaction.Target; if ((null != head) && this.weakTransaction.IsAlive) { head = OleDbTransaction.TransactionUpdate(head); // either we are wrong or finalize was called and object still alive Debug.Assert(null != head, "unexcpted Transaction state"); } // else transaction has finalized on user if (null != head) { if (null == transaction) { // valid transaction exists and cmd doesn't have it throw ADP.TransactionRequired(method); } else { OleDbTransaction tail = OleDbTransaction.TransactionLast(head); if (tail != transaction) { if (tail.Connection != transaction.Connection) { throw ADP.TransactionConnectionMismatch(); } // else cmd has incorrect transaction throw ADP.TransactionCompleted(); } // else cmd has correct transaction return(transaction); } } else { // cleanup for Finalized transaction this.weakTransaction = null; } } else if ((null != transaction) && (null != transaction.Connection)) { throw ADP.TransactionConnectionMismatch(); } // else no transaction and cmd is correct // if transactionObject is from this connection but zombied // and no transactions currently exists - then ignore the bogus object return(null); }
protected override void Deactivate() { // used by both managed and native pooling NotifyWeakReference(OleDbReferenceCollection.Closing); if (_unEnlistDuringDeactivate) { // Un-enlist transaction as OLEDB connection pool is unaware of managed transactions. EnlistTransactionInternal(null); } OleDbTransaction?transaction = LocalTransaction; if (null != transaction) { LocalTransaction = null; // required to rollback any transactions on this connection // before releasing the back to the oledb connection pool transaction.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { // release mananged objects // the DataReader takes ownership of the parameter Bindings // this way they don't get destroyed when user calls OleDbCommand.Dispose // when there is an open DataReader unchecked { _changeID++; } // in V1.0, V1.1 the Connection,Parameters,CommandText,Transaction where reset ResetConnection(); _transaction = null; _parameters = null; CommandText = null; } // release unmanaged objects base.Dispose(disposing); // notify base classes }
/*protected virtual*/ internal OleDbHResult RollbackInternal(bool exceptionHandling) { OleDbHResult hr = 0; if (null != _transaction) { if (null != _nestedTransaction) { OleDbTransaction?transaction = (OleDbTransaction?)_nestedTransaction.Target; if ((null != transaction) && _nestedTransaction.IsAlive) { hr = transaction.RollbackInternal(exceptionHandling); if (exceptionHandling && (hr < 0)) { SafeNativeMethods.Wrapper.ClearErrorInfo(); return(hr); } } _nestedTransaction = null; } hr = _transaction.Abort(); _transaction.Dispose(); _transaction = null; if (hr < 0) { if (exceptionHandling) { ProcessResults(hr); } else { SafeNativeMethods.Wrapper.ClearErrorInfo(); } } } return(hr); }
internal OleDbTransaction(OleDbConnection connection, OleDbTransaction?transaction, IsolationLevel isolevel) { _parentConnection = connection; _parentTransaction = transaction; switch (isolevel) { case IsolationLevel.Unspecified: // OLE DB doesn't support this isolevel on local transactions isolevel = IsolationLevel.ReadCommitted; break; case IsolationLevel.Chaos: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: break; default: throw ADP.InvalidIsolationLevel(isolevel); } _isolationLevel = isolevel; }
/// <summary> /// Creates an open data source using the supplied connection and optional transaction. /// </summary> /// <param name="connection">The connection to wrap.</param> /// <param name="transaction">The transaction to wrap.</param> /// <returns>IOpenDataSource.</returns> public AccessOpenDataSource CreateOpenDataSource(OleDbConnection connection, OleDbTransaction?transaction = null) { return(new AccessOpenDataSource(this, connection, transaction)); }
/// <summary> /// Creates an open data source using the supplied connection and optional transaction. /// </summary> /// <param name="connection">The connection.</param> /// <param name="transaction">The transaction.</param> /// <returns>OleDbSqlServerOpenDataSource.</returns> public OleDbSqlServerOpenDataSource CreateOpenDataSource(OleDbConnection connection, OleDbTransaction?transaction = null) { return(new OleDbSqlServerOpenDataSource(this, connection, transaction)); }
public OleDbCommand(string?cmdText, OleDbConnection?connection, OleDbTransaction?transaction) : this() { CommandText = cmdText; Connection = connection; Transaction = transaction; }
internal OleDbTransaction?ValidateTransaction(OleDbTransaction?transaction, string method) { return(GetOpenConnection().ValidateTransaction(transaction, method)); }