如何使用MVC Mini Profiler连接SqlDataAdapter来分析数据库操作 [英] How to hook up SqlDataAdapter to profile db operations with mvc mini profiler
问题描述
我查找了我该如何实例化Profiled DataAdapter以便与MVC MINI PROFILER一起使用?,但这也无法回答我的问题.
I looked up How could I instantiate a Profiled DataAdapter to use with MVC MINI PROFILER? but this also did not answer my question.
我在SqlDatasource类中有一些类似的代码-
I have some code like this in SqlDatasource class -
protected SqlCommand sqlCommand;
public SqlDatasource(String query, String connectionString) : this(connectionString)
{
this.sqlCommand.CommandText = query;
}
public DataTable getResults()
{
DataTable table = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(this.sqlCommand);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter);
adapter.Fill(table);
return table;
}
我想要一种在调用getResults()时挂接到SqlDataAdapter的方法.我进行了很多搜索,但似乎还没有办法做到这一点.
I want a way to hook into the SqlDataAdapter when getResults() gets called. I searched a lot but there did not seem a way for me to do this yet.
谢谢.
推荐答案
为此提供了一个类ProfiledDbDataAdapter
,您可以使用它包装在现有的SqlDataAdapter
周围.
There's a class ProfiledDbDataAdapter
provided for this that you can use wrapped around your existing SqlDataAdapter
.
当我尝试使用它时,我发现我需要使用Fill(DataSet)
方法而不是Fill(DataTable)
,否则我总是收到一个错误在调用'Fill'之前,尚未初始化SelectCommand属性".尽管同时设置了两个适配器的SelectCommand
属性.
When I tried using it I found I needed to use the Fill(DataSet)
method instead of Fill(DataTable)
else I always received an error "The SelectCommand property has not been initialized before calling 'Fill'." despite setting both adapter's SelectCommand
properties.
这篇关于如何使用MVC Mini Profiler连接SqlDataAdapter来分析数据库操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!