使用MiniProfiler直接调用ADO.net
对于那些在C#和剖析中极客的人来说,这个问题将是愚蠢的。
我是c#的新手(基本上是一个c ++开发人员)。 如果它使用dbproviderfactory
,我可以分析数据库查询,但是当直接使用它时,我无法分析ado.net调用(原始SqlConnection
和SqlCommand
)。 我遇到了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);
- ADO.NET:安全地为所有VarChar参数指定SqlParameter.Size的-1?
- 错误:在传递带有已修改行的DataRow集合时,Update需要有效的UpdateCommand
- 如何在DataGridView中获取选定的DataRow?
- CommandBehavior.SequentialAccess是否有任何性能提升?
- 使用SqlConnection.GetSchema仅获取表(无视图)
- C# – ADO.NET的一些高性能最佳实践/技巧是什么?
- 使用c#从存储过程读出参数时出现问题
- 以编程方式使用C#更新MS Access数据库中的链接表
- 在SQL Server 2014中使用TransactionScope围绕存储过程与事务