Can Glimpse provide diagnostics when using SqlClient namespace classes

I downloaded Glimpse and the Glimpse.ADO extension and installed it on my test instance.

I thought that I would get a capture of any sql that was executed, but it does not seem to capture commands with the way our code is written.

using (var conn = new SqlConnection(cString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "Select count(*) from table"; cmd.CommandType = CommandType.Text; txtResult2.Text = cmd.ExecuteScalar().ToString(); conn.Close(); } 

I can get it to provide information from a test page with sql code written like this:

  var factory =DbProviderFactories.GetFactory(cString.ProviderName); using (var connection = factory.CreateConnection()) { connection.ConnectionString = connectionString.ConnectionString; connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT COUNT(*) FROM table"; command.CommandType = CommandType.Text; txtResult1.Text = command.ExecuteScalar().ToString(); } } 

However, I have too many places in my code to modify, if I can only capture data using this dbProviderFactories method.

Is there a way to get Glimpse.ADO to work with the System.Data.SqlClient.SqlConnection class? Is there another Glimpse extension that works with this namespace?

Is there any other way to solve this problem?

+7
source share
2 answers

I agree with @StriplingWarrior, using vendor factories will make your code drier and follow best practices. DbProviderFactories really the best way to do this, and your code will obviously not rely on Glimpse.

However, if you really want to just upgrade with your existing application code, Glimpse will support you with the following changes:

 using (var conn = new GlimpseDbConnection(new SqlConnection(cString)) { conn.Open(); DbCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select count(*) from table"; cmd.CommandType = CommandType.Text; txtResult2.Text = cmd.ExecuteScalar().ToString(); conn.Close(); } 

In the above example, a command is created using the CreateCommand() method, which eliminates the need to bind the command and connection.

Alternatively, you can also explicitly create a command as follows:

 conn.Open(); DbCommand cmd = new GlimpseDbCommand(new SqlCommand()); cmd.Connection = conn; cmd.CommandText = "Select count(*) from table"; cmd.CommandType = CommandType.Text; 

Finally, more documentation on the SQL tab can be obtained by clicking the ? in the Glimpse user interface when you select a tab, or by going to our SQL documentation on getGlimpse.com . ( I will add this information to this page for future reference. )

+6
source

In the "Problems" section of the Glimpse website ...

Getting a look at working with manually created SQL joins / commands

http://getglimpse.com/Docs/Manual-ADO-Integration

+1
source

All Articles