private void CheckSQLDebugOnConnect() { string str; uint currentProcessId = (uint) SafeNativeMethods.GetCurrentProcessId(); if (ADP.IsPlatformNT5) { str = @"Global\SqlClientSSDebug"; } else { str = "SqlClientSSDebug"; } str = str + currentProcessId.ToString(CultureInfo.InvariantCulture); IntPtr hFileMappingObject = System.Data.Common.NativeMethods.OpenFileMappingA(4, false, str); if (ADP.PtrZero != hFileMappingObject) { IntPtr ptr2 = System.Data.Common.NativeMethods.MapViewOfFile(hFileMappingObject, 4, 0, 0, IntPtr.Zero); if (ADP.PtrZero != ptr2) { SqlDebugContext sdc = new SqlDebugContext { hMemMap = hFileMappingObject, pMemMap = ptr2, pid = currentProcessId }; this.CheckSQLDebug(sdc); this._sdc = sdc; } } }
private static void RefreshMemoryMappedData(SqlDebugContext sdc) { MEMMAP memmap = (MEMMAP) Marshal.PtrToStructure(sdc.pMemMap, typeof(MEMMAP)); sdc.dbgpid = memmap.dbgpid; sdc.fOption = memmap.fOption == 1; Encoding encoding = Encoding.GetEncoding(0x4e4); sdc.machineName = encoding.GetString(memmap.rgbMachineName, 0, memmap.rgbMachineName.Length); sdc.sdiDllName = encoding.GetString(memmap.rgbDllName, 0, memmap.rgbDllName.Length); sdc.data = memmap.rgbData; }
public override void Close() { IntPtr ptr; Bid.ScopeEnter(out ptr, "<sc.SqlConnection.Close|API> %d#", this.ObjectID); try { SqlStatistics statistics = null; SNIHandle target = null; RuntimeHelpers.PrepareConstrainedRegions(); try { target = SqlInternalConnection.GetBestEffortCleanupTarget(this); statistics = SqlStatistics.StartTimer(this.Statistics); lock (this.InnerConnection) { this.InnerConnection.CloseConnection(this, this.ConnectionFactory); } if (this.Statistics != null) { ADP.TimerCurrent(out this._statistics._closeTimestamp); } } catch (OutOfMemoryException exception3) { this.Abort(exception3); throw; } catch (StackOverflowException exception2) { this.Abort(exception2); throw; } catch (ThreadAbortException exception) { this.Abort(exception); SqlInternalConnection.BestEffortCleanup(target); throw; } finally { SqlStatistics.StopTimer(statistics); } } finally { SqlDebugContext context = this._sdc; this._sdc = null; Bid.ScopeLeave(ref ptr); if (context != null) { context.Dispose(); } } }
private void CheckSQLDebug(SqlDebugContext sdc) { uint currentThreadId = (uint) AppDomain.GetCurrentThreadId(); RefreshMemoryMappedData(sdc); if (!sdc.active && sdc.fOption) { sdc.active = true; sdc.tid = currentThreadId; try { this.IssueSQLDebug(1, sdc.machineName, sdc.pid, sdc.dbgpid, sdc.sdiDllName, sdc.data); sdc.tid = 0; } catch { sdc.active = false; throw; } } if (sdc.active) { if (!sdc.fOption) { sdc.Dispose(); this.IssueSQLDebug(0, null, 0, 0, null, null); } else if (sdc.tid != currentThreadId) { sdc.tid = currentThreadId; try { this.IssueSQLDebug(2, null, sdc.pid, sdc.tid, null, null); } catch { sdc.tid = 0; throw; } } } }