public override DbTransaction BeginTransaction(IsolationLevel isolationLevel) { OleDbConnection outerConnection = Connection; if (null != LocalTransaction) { throw ADP.ParallelTransactionsNotSupported(outerConnection); } object unknown = null; OleDbTransaction transaction; try { transaction = new OleDbTransaction(outerConnection, null, isolationLevel); Debug.Assert(null != _datasrcwrp, "ITransactionLocal: null datasource"); Debug.Assert(null != _sessionwrp, "ITransactionLocal: null session"); unknown = _sessionwrp.ComWrapper(); UnsafeNativeMethods.ITransactionLocal value = (unknown as UnsafeNativeMethods.ITransactionLocal); if (null == value) { throw ODB.TransactionsNotSupported(Provider, (Exception)null); } transaction.BeginInternal(value); } finally { if (null != unknown) { Marshal.ReleaseComObject(unknown); } } LocalTransaction = transaction; return(transaction); }
public OleDbTransaction Begin(IsolationLevel isolevel) { if (null == _transaction) { throw ADP.TransactionZombied(this); } else if ((null != _nestedTransaction) && _nestedTransaction.IsAlive) { throw ADP.ParallelTransactionsNotSupported(Connection); } // either the connection will be open or this will be a zombie OleDbTransaction transaction = new OleDbTransaction(_parentConnection, this, isolevel); _nestedTransaction = new WeakReference(transaction, false); UnsafeNativeMethods.ITransactionLocal wrapper = null; try { wrapper = (UnsafeNativeMethods.ITransactionLocal)_transaction.ComWrapper(); transaction.BeginInternal(wrapper); } finally { if (null != wrapper) { Marshal.ReleaseComObject(wrapper); } } return(transaction); }
// <fxcop ignore="MethodsInTypesWithIntPtrFieldAndFinalizeMethodRequireGCKeepAlive"/> private void Dispose(bool disposing) { if (disposing) // release mananged objects { DisposeManaged(); RollbackInternal(false); } // release unmanaged objects this.localTransaction = null; if (IntPtr.Zero != this.iunknown) { // create a new UnsafeNativeMethods.ITransactionLocal from IntPtr // to avoid using existing managed wrapper on the com object try { object local = Marshal.GetObjectForIUnknown(this.iunknown); UnsafeNativeMethods.ITransactionLocal transaction = (UnsafeNativeMethods.ITransactionLocal)local; transaction.Abort(0, 0, 0); Marshal.Release(this.iunknown); } catch (Exception) { } this.iunknown = IntPtr.Zero; } }
private int RollbackInternal(bool exceptionHandling) { int hr = 0; if (null != this.localTransaction) { Marshal.Release(this.iunknown); this.iunknown = IntPtr.Zero; // there is no recovery if Rollback throws an exception UnsafeNativeMethods.ITransactionLocal local = this.localTransaction; this.localTransaction = null; if (null != this.weakTransaction) { OleDbTransaction transaction = (OleDbTransaction)this.weakTransaction.Target; if ((null != transaction) && this.weakTransaction.IsAlive) { hr = transaction.RollbackInternal(exceptionHandling); GC.KeepAlive(transaction); GC.SuppressFinalize(transaction); if (hr < 0) { SafeNativeMethods.ClearErrorInfo(); return(hr); } } this.weakTransaction = null; } #if DEBUG if (AdapterSwitches.OleDbTrace.TraceInfo) { ODB.Trace_Begin("ITransactionLocal", "Abort"); } #endif hr = local.Abort(0, 0, 0); #if DEBUG if (AdapterSwitches.OleDbTrace.TraceInfo) { ODB.Trace_End("ITransactionLocal", "Abort", hr); } #endif if (hr < 0) { if (exceptionHandling) { ProcessResults(hr); } else { SafeNativeMethods.ClearErrorInfo(); } } } return(hr); }
private void CommitInternal() { if (null == this.localTransaction) { return; } if (null != this.weakTransaction) { OleDbTransaction transaction = (OleDbTransaction)this.weakTransaction.Target; if ((null != transaction) && this.weakTransaction.IsAlive) { transaction.CommitInternal(); } this.weakTransaction = null; } #if DEBUG if (AdapterSwitches.OleDbTrace.TraceInfo) { ODB.Trace_Begin("ITransactionLocal", "Commit"); } #endif int hr; hr = this.localTransaction.Commit(0, /*OleDbTransactionControl.SynchronousPhaseTwo*/ 2, 0); #if DEBUG if (AdapterSwitches.OleDbTrace.TraceInfo) { ODB.Trace_End("ITransactionLocal", "Commit", hr); } #endif if (hr < 0) { if (ODB.XACT_E_NOTRANSACTION == hr) { Marshal.Release(this.iunknown); this.iunknown = IntPtr.Zero; this.localTransaction = null; DisposeManaged(); } ProcessResults(hr); } if (IntPtr.Zero != this.iunknown) { Marshal.Release(this.iunknown); this.iunknown = IntPtr.Zero; } // if an exception is thrown, user can try to commit their transaction again this.localTransaction = null; DisposeManaged(); GC.KeepAlive(this); GC.SuppressFinalize(this); }
internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction) { OleDbHResult hr; _transaction = new WrappedTransaction(transaction, (int)_isolationLevel, out hr); if (hr < 0) { _transaction.Dispose(); _transaction = null; ProcessResults(hr); } }
internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction) { OleDbHResult result; this._transaction = new WrappedTransaction(transaction, (int)this._isolationLevel, out result); if (result < OleDbHResult.S_OK) { this._transaction.Dispose(); this._transaction = null; this.ProcessResults(result); } }
internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out _); if (0 <= hr) { _mustComplete = true; } } }
internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction) { int transactionLevel = 0; Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB>\n"); RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out transactionLevel); if (0 <= hr) { _mustComplete = true; } } Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB|RET> %08X{HRESULT}\n", hr); }
internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction, IsolationLevel isolevel) { switch (isolevel) { case IsolationLevel.Unspecified: case IsolationLevel.Chaos: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: break; default: throw ADP.InvalidIsolationLevel((int)isolationLevel); } int hr, transactionLevel = 0; #if DEBUG if (AdapterSwitches.OleDbTrace.TraceInfo) { ODB.Trace_Begin("ITransactionLocal", "StartTransaction", this.isolationLevel.ToString("G")); } #endif // $UNDONE: how is it possible to guard against something like ThreadAbortException // when transaction started, but aborted before localTransaction is set // so we know to rollback the transaction for when connection is returned to the pool hr = transaction.StartTransaction((int)isolevel, 0, null, out transactionLevel); #if DEBUG if (AdapterSwitches.OleDbTrace.TraceInfo) { ODB.Trace_End("ITransactionLocal", "StartTransaction", hr, "TransactionLevel=" + transactionLevel); } #endif if (hr < 0) { ProcessResults(hr); } this.isolationLevel = isolevel; this.localTransaction = transaction; this.iunknown = Marshal.GetIUnknownForObject(transaction); GC.KeepAlive(this); }
public OleDbTransaction Begin(System.Data.IsolationLevel isolevel) { OleDbTransaction transaction2; IntPtr ptr; OleDbConnection.ExecutePermission.Demand(); Bid.ScopeEnter(out ptr, "<oledb.OleDbTransaction.Begin|API> %d#, isolevel=%d{IsolationLevel}", this.ObjectID, (int)isolevel); try { if (this._transaction == null) { throw ADP.TransactionZombied(this); } if ((this._nestedTransaction != null) && this._nestedTransaction.IsAlive) { throw ADP.ParallelTransactionsNotSupported(this.Connection); } OleDbTransaction target = new OleDbTransaction(this._parentConnection, this, isolevel); this._nestedTransaction = new WeakReference(target, false); UnsafeNativeMethods.ITransactionLocal transaction = null; try { transaction = (UnsafeNativeMethods.ITransactionLocal) this._transaction.ComWrapper(); target.BeginInternal(transaction); } finally { if (transaction != null) { Marshal.ReleaseComObject(transaction); } } transaction2 = target; } finally { Bid.ScopeLeave(ref ptr); } return(transaction2); }
public OleDbTransaction Begin(IsolationLevel isolevel) { OleDbConnection.ExecutePermission.Demand(); // MDAC 81476 IntPtr hscp; Bid.ScopeEnter(out hscp, "<oledb.OleDbTransaction.Begin|API> %d#, isolevel=%d{IsolationLevel}", ObjectID, (int)isolevel); try { if (null == _transaction) { throw ADP.TransactionZombied(this); } else if ((null != _nestedTransaction) && _nestedTransaction.IsAlive) { throw ADP.ParallelTransactionsNotSupported(Connection); } // either the connection will be open or this will be a zombie OleDbTransaction transaction = new OleDbTransaction(_parentConnection, this, isolevel); _nestedTransaction = new WeakReference(transaction, false); UnsafeNativeMethods.ITransactionLocal wrapper = null; try { wrapper = (UnsafeNativeMethods.ITransactionLocal)_transaction.ComWrapper(); transaction.BeginInternal(wrapper); } finally { if (null != wrapper) { Marshal.ReleaseComObject(wrapper); } } return(transaction); } finally { Bid.ScopeLeave(ref hscp); } }