/// <summary> /// Commands the executing. /// </summary> /// <param name="command">The command.</param> /// <param name="interceptionContext">The interception context.</param> /// <param name="userState">State of the user.</param> /// <inheritdoc /> private void CommandExecuting(DbCommand command, DbCommandInterceptionContext interceptionContext, out object userState) { userState = null; if (!interceptionContext.DbContexts.Any(a => this.DbContextList.Contains(a) || this.EnableForAllDbContexts)) { return; } if (!(command is System.Data.SqlClient.SqlCommand)) { // not a SQL command. Nothing is going to the Database. Probably interception. return; } if (SessionId.IsNotNullOrWhiteSpace()) { if (System.Web.HttpContext.Current?.Session?.SessionID != SessionId) { return; } } var incrementedCallCount = Interlocked.Increment(ref DebugHelper._callCounts); if (!TimingsOnly && !SummaryOnly) { StringBuilder sbDebug = GetSQLBlock(command, incrementedCallCount); _sqlOutput.Append(sbDebug); System.Diagnostics.Debug.Write(sbDebug.ToString()); } var sqlConnection = command.Connection as System.Data.SqlClient.SqlConnection; sqlConnection.StatisticsEnabled = true; sqlConnection.ResetStatistics(); if (userState == null) { userState = new DebugHelperUserState { CallNumber = incrementedCallCount, Stopwatch = Stopwatch.StartNew() }; } }