Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL dependencies do not work with Microsoft.Data.SqlClient in 2.11 with ASP.NET MVC 5 app #1347

Closed
stebet opened this issue Oct 3, 2019 · 5 comments

Comments

@stebet
Copy link
Contributor

stebet commented Oct 3, 2019

If you are reporting bug/issue, please provide detailed Repro instructions.

Repro Steps

  1. Create a new ASP.NET MVC 5 application running on .NET Framework 4.7.2
  2. Add Application Insights using Visual Studio
  3. Add a NuGet reference to Microsoft.Data.SqlClient
  4. Add a NuGet reference to Dapper (optional, just used here for simplicity)
  5. Trigger the following code to run, for example in the Index action on the HomeController (add your appropriate SQL connection values).
public ActionResult Index()
{
    using(SqlConnection conn = new SqlConnection("Server=localhost;Database=master;Trusted_Connection=True;"))
    {
        string[] names = conn.Query<string>("SELECT name FROM sys.tables").ToArray();
        return View();
    }
}

Actual Behavior

An error can be seen in the Debug output window, with the following information:
ERROR: Exception in Command Processing for EventSource Microsoft-AdoNet-SystemData: Event BeginExecute is givien event ID 2 but 1 was passed to WriteEvent.

Expected Behavior

SQL dependency is properly picked up and reported, without errors.

Version Info

SDK Version : 2.11
.NET Version : .NET Framework 4.7.2
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) :
OS : VisualStudio
Hosting Info (IIS/Azure WebApps/ etc) : IIS

@stebet
Copy link
Contributor Author

stebet commented Oct 3, 2019

I seem to have tracked this down to a bug in the Microsoft.Data.SqlClient library, waiting for a response from there.

@cijothomas
Copy link
Contributor

@stebet Thanks for investigating this!
Indeed this EventSource is how ApplicationInsights tracks SQL Dependency in full framework.
https://github.com/microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/DependencyCollector/Shared/Implementation/FrameworkSqlEventListener.cs#L23

We have the same issue if Statusmonitor/profiler is enabled as well, as Application Insights is not decorating Microsoft.Data.XXX.
https://github.com/microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/DependencyCollector/Shared/Implementation/ProfilerRuntimeInstrumentation.cs#L78

@TimothyMothra TimothyMothra transferred this issue from microsoft/ApplicationInsights-dotnet-server Dec 4, 2019
@michaelpaulus
Copy link

Is there any update on this? I just got done upgrading all of our projects to EF Core. I didn't realize this was an issue until now.

@stebet
Copy link
Contributor Author

stebet commented Jan 14, 2020

If you are using Microsoft.Data.SqlClient, you should be fine if you upgrade to the latest release (1.1.0 as of this comment).

@stebet
Copy link
Contributor Author

stebet commented Jan 14, 2020

This issue was fixed with this PR: dotnet/SqlClient#241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants