使用MiniProfiler直接调用ADO.net

对于那些在C#和剖析中极客的人来说,这个问题将是愚蠢的。

我是c#的新手(基本上是一个c ++开发人员)。 如果它使用dbproviderfactory ,我可以分析数据库查询,但是当直接使用它时,我无法分析ado.net调用(原始SqlConnectionSqlCommand )。 我遇到了Miniprofiler代码,他们也可以直接调用ADO.net调用。 我只是不知道如何使用它(将其集成到我的探查器中)。

我的代码是

  SqlConnection myConn = new SqlConnection(@"Server=192.168.23.99;Initial Catalog=cat1;User ID=user21;Password=userpwd"); SqlCommand myCommand = new SqlCommand("select * from table1", myConn); SqlDataReader dataReader; System.Threading.Thread.Sleep(5000); try { myConn.Open(); dataReader = myCommand.ExecuteReader(); GridView1.DataSource = dataReader; GridView1.DataBind(); dataReader.Close(); myCommand.Dispose(); myConn.Close(); } catch (System.Exception ex) { Response.Write(ex.ToString()); } 

当执行上面的代码时,将如何调用MiniProfiler中的类? 当我的Web应用程序调用SqlCommand(..)时,如何调用这些类(希望类名是SimpleProfiledDbCommand )。

需要更好地澄清这一点。

根据文档 ,您需要使用提供的能够跟踪查询的ProfiledDbConnection包装SqlConnection

 SqlConnection underlyingConn = new SqlConnection(@"Server=192.168.23.99;Initial Catalog=cat1;User ID=user21;Password=userpwd"); SqlConnection myConn = new StackExchange.Profiling.Data.ProfiledDbConnection(underlyingConn, MiniProfiler.Current);