public void OnError(DbCommand profiledDbCommand, StackExchange.Profiling.Data.ExecuteType executeType, Exception exception) { var formatter = new StackExchange.Profiling.SqlFormatters.SqlServerFormatter(); var timing = new StackExchange.Profiling.SqlTiming(profiledDbCommand, executeType, null); exception.Data["SQL"] = formatter.FormatSql(timing); this.wrapped.OnError(profiledDbCommand, executeType, exception); }