I am trying to add Glimpse to my web application. It is working but I am missing one of the best features - i.e. the ability to see how many SQL queries run on each page.
My application is using rather old school Microsoft.Practices.EnterpriseLibrary.Data; to create a database instance and then run a stored proc to return data.
I found a Glimpse EnterpriseLibrary.Data nuget package here which I thought might work but it is not what I need
Looking at the Microsoft.Practices.EnterpriseLibrary.Data; dll in my DAL layer it is Version 5.0.414.0 and Runtime Version v2.0.50727. The Enterprise library nuget package above has a dependency on a higher version of the Enterprise library.data and I dont want to upgrade this in case it breaks something.
This is how my current DB layer code looks:
// Some method to get data
Database db = MyDatabaseFactory.MyDB;
var sqlCmd = new SqlCommand(StoredProcedures.MyStoredProc);
sqlCmd.CommandType = CommandType.StoredProcedure;
using (IDataReader dr = db.ExecuteReader(sqlCmd))
{
//Impl removed for brevity
My DB Factory then looks like:
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace MyProj.DAL
{
class MyDatabaseFactory
{
internal static Database MyDB
{
get
{
return DatabaseFactory.CreateDatabase("MyDB");
}
}
Is there anyway I can use reflection so that Glimpse will be able to inspect the SQL running?
Was thinking I could possibly use something similar to the code that the Nuget package above uses which is - just not sure what changes to make so thet GlimpseSqlDatabase inherits from Database rather than SqlDatabase:
public class GlimpseSqlDatabase : SqlDatabase
{
private static readonly FieldInfo dbProviderFactoryField =
typeof(Database).GetField("dbProviderFactory", BindingFlags.Instance | BindingFlags.NonPublic);
public GlimpseSqlDatabase(string connectionString)
: base(connectionString)
{
dbProviderFactoryField.SetValue(this, DbProviderFactories.GetFactory("System.Data.SqlClient"));
}
}