// <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); }