【问题标题】:SQL command text through ETW events for the SQL ETW event sourceSQL ETW 事件源的 ETW 事件的 SQL 命令文本
【发布时间】:2018-02-26 15:28:20
【问题描述】:

使用漂亮的 EtwStream 库可以监听 ETW 事件。但是,在侦听 SQL 提供程序时,不会捕获命令文本:

ObservableEventListener.FromTraceEvent(WellKnownEventSources.SqlEventSource).LogToConsole(ev => ev.ToString());

知道如何通过 ETW 发出这些数据吗?

【问题讨论】:

    标签: sql .net sql-server etw


    【解决方案1】:

    这个属性只为存储过程填充:

            private void WriteBeginExecuteEvent()
            {
                if (SqlEventSource.Log.IsEnabled() && Connection != null)
                {
                    string commandText = CommandType == CommandType.StoredProcedure ? CommandText : string.Empty;
                    SqlEventSource.Log.BeginExecute(GetHashCode(), Connection.DataSource, Connection.Database, commandText);
                }
            }
    

    (来源:https://referencesource.microsoft.com/#System.Data/fx/src/data/System/Data/SqlClient/SqlCommand.cs,cc46bed589639792

    您只能将查询重写为存储过程调用或编写自己的 etw 提供程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2019-05-13
      • 2013-12-10
      • 2011-05-04
      • 1970-01-01
      • 2019-06-03
      相关资源
      最近更新 更多