Glimpse is a really nice tracing and diagnostic tool for what’s happening on the server in an ASP.NET app.

image

It has a tab for showing the SQL and the query parameters being passed to SQL Server, but my tab looked like this when using Dapper dot net, a light-weight ORM that takes your SQL result and maps it to a C# object:

image

I knew Glimpse worked with ADO.NET, I had installed that plugin, and Dapper was using ADO.NET somewhere inside its framework, but my SQL tab was disabled.  I thought maybe I needed to install a Glimpse Dapper plugin, but there was none on the official Glimpse plugins page.

I found this unofficial Glimpse Dapper plugin, but it still seemed like it was trying too hard.  This should be easier.

I was getting my Dapper SQL connection through a factory like this:

    public static class ConnectionFactory
    {
        public static IDbConnection CreateConnection(string connectionString)
        {
            var cnn = new SqlConnection(connectionString);
            cnn.Open();

            return cnn;
        }
    }

I finally found the Glimpse ADO integration help, and it said, “If you're not using an ADO connection that uses the DbProviderFactories class, Glimpse won't collect any data for the SQL tab (out of the box).”

Oh.  Ok.  So I changed my code to this:

    public static class ConnectionFactory
    {
        public static IDbConnection CreateConnection(string connectionString)
        {
            var factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
            var cnn = factory.CreateConnection();
            cnn.ConnectionString = connectionString;
            cnn.Open();

            return cnn;
        }
    }

and now the SQL and parameters are showing on the Glimpse SQL tab:

image

Yay!