【问题标题】:It is capturing SQL command text supported in .net 4.6 application in Application Insights?它正在捕获 Application Insights 中 .net 4.6 应用程序中支持的 SQL 命令文本?
【发布时间】:2017-08-29 19:59:54
【问题描述】:

想象一下 .NET 4.6 控制台应用程序,它使用 ADO.NET 查询 sql 数据库。

    static void Main(string[] args)
    {
        TelemetryConfiguration.Active.InstrumentationKey = "my key";

        var tc = new TelemetryClient(TelemetryConfiguration.Active);

        tc.TrackEvent("App start");

        string ConnString = "Data Source=localhost;Initial Catalog=MyDb;Persist Security Info=True;User ID=sa;Password=****;MultipleActiveResultSets=True";
        string SqlString = "Select * From Customers";
        using (SqlConnection conn = new SqlConnection(ConnString))
        {
            using (SqlCommand cmd = new SqlCommand(SqlString, conn))
            {
                cmd.CommandType = CommandType.Text;

                conn.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    var res = reader.Read();
                }
            }
        }


        tc.TrackEvent("App stop");
        tc.Flush();
        Thread.Sleep(5000);
    }

在这种情况下是否支持捕获 SQL 命令文本?还是仅在 IIS 和 Azure App 上受支持?

在此示例中,我希望在依赖事件中的 Application Insights 上看到文本“Select * From Customers”,但该文本不存在。只有少数其他属性(如持续时间、客户端 IP 等)有依赖关系,但没有 sql 文本。

【问题讨论】:

    标签: .net azure azure-application-insights


    【解决方案1】:

    sql 语句由“状态监视器”收集,该监视器在运行时作为 .net 分析器在 Web 应用程序上运行。

    https://docs.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-dependencies

    我会四处打听,但我很确定要在非网络应用程序上连接它并不容易,而不需要跳过很多 圈.

    【讨论】:

    • 在与@dmitry-matveev 交谈之后,理论上 是可能的,但这种理论可能不值得实际尝试。它需要很多东西,你最好使用自定义事件或自定义属性手动记录自己,除非你有一个非常大且复杂的控制台应用程序要尝试检测。
    • 谢谢。正如你所说,我将手动记录所需的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 2020-08-02
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 2016-11-07
    相关资源
    最近更新 更多