【发布时间】:2022-12-14 21:40:41
【问题描述】:
我在将 EnableSqlCommandTextInstrumentation 添加到我的 MVC .Net Framework 4.7.2 项目时遇到问题/我们使用 IIS 服务器。
按照自动安装步骤后,我遵循了这个文档 https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-dependencies高级 SQL 跟踪以获得完整的 SQL 查询
我在 ApplicationInsights.config 中添加了必要的配置并安装了 Microsoft.Data.SqlClient 最新版本(问题发生时为 4.8.4)
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
<EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
我根本不理解的文档的唯一部分是:
In the preceding cases, the proper way of validating that the instrumentation engine is correctly installed is by validating that the SDK version of collected DependencyTelemetry is rddp. Use of rdddsd or rddf indicates dependencies are collected via DiagnosticSource or EventSource callbacks, so the full SQL query won't be captured.
我在 Azure 上的 ApplicationInsights 收到了所有正确的数据,但它仍然缺少 SQL 命令的详细信息。
更新 1
正如建议的那样,我运行了查询并发现在我的 SQL 命令工作的 .Net Core 应用程序中我有 rdddsc:2.21.0-429 但在我的 .Net Framework 应用程序中我有 rddf:2.15.0-44797。我在我的 WebView 项目和我的业务项目中都安装了 Microsoft.Data.SqlClient 块。
我唯一拥有 System.Data.SqlClient 的地方是在我的商业项目上的 app.config 中。
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
我将其更改为Microsoft.Data.SqlClient(不确定这样做是否正确)但我仍然收到 rddf:2.15.0-44797
更新 2 和解决方案
问题确实是我的项目使用的是 System.Data.SqlClient。
我使用的是 .net Framework 4.7.2,所以我将所有项目更新为 4.8。 这是一个对我有很大帮助的资源,我按照这些步骤操作并且它起作用了它还解释了 System.Data.SqlClient 的问题。 https://erikej.github.io/ef6/sqlserver/2021/08/08/ef6-microsoft-data-sqlclient.html
长话短说 1- 在包含您的上下文的项目中安装包。
Install-Package ErikEJ.EntityFramework.SqlServer -Version 1.0.0-rc5
2-将此数据注释添加到您的上下文中。
[DbConfigurationType(typeof(System.Data.Entity.SqlServer.MicrosoftSqlDbConfiguration))]
3-通过更改提供程序将项目中的 app.config 更改为不使用 System.Data.SqlClient
<entityFramework>
<providers>
<provider invariantName="Microsoft.Data.SqlClient" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices,
ErikEJ.EntityFramework.SqlServer" />
</providers>
</entityFramework>
4- 如果您参考例如 SqlParameter,请删除从 System.Data.SqlClient 到 Microsoft.Data.SqlClient 的任何使用语句。
【问题讨论】:
标签: c# .net asp.net-mvc azure-application-insights