使用MiniProfiler进行直接ADO.net调用 [英] Using MiniProfiler for direct ADO.net calls
问题描述
对于那些精通C#和Profiler的人来说,这个问题将是愚蠢的。
This question will be silly for those who are geeks in C# and profilers.
我是c#的新手(基本上是c ++开发人员)。如果数据库查询使用 dbproviderfactory
,我可以对其进行概要分析,但是当直接使用ado.net调用时,我无法对其进行概要分析(原始 SqlConnection
和 SqlCommand
)。我遇到了Miniprofiler代码,他们还在其中分析了直接的ADO.net调用。我只是不知道如何使用它(将其集成到我的分析器中)。
I am new to c# (basically a c++ developer) . I can profile the database queries if it use dbproviderfactory
, but i cannot profile the ado.net calls when it is used directly(raw SqlConnection
& SqlCommand
). I came across the Miniprofiler code where they also profile direct ADO.net calls. I just dont know how to use it ( integrate it in my profiler ).
我的代码是
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
)?
When the above code gets executed , how will the classes in MiniProfiler will be called? How to make those classes(hope the class name is SimpleProfiledDbCommand
) called when my web application calls SqlCommand(..).?
对此需要更好的说明。
推荐答案
文档,您需要使用提供的<$包装 SqlConnection
c $ c> ProfiledDbConnection 能够跟踪您的查询:
According to the documentation, you need to wrap your SqlConnection
with the provided ProfiledDbConnection
that is able to track your queries:
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);
这篇关于使用MiniProfiler进行直接ADO.net调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!