How to hook up SqlDataAdapter to profile db operations with mvc mini profiler

人盡茶涼 提交于 2019-12-18 08:53:57

问题


I looked up How could I instantiate a Profiled DataAdapter to use with MVC MINI PROFILER? but this also did not answer my question.

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;
    }

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.

Thanks.


回答1:


There's a class ProfiledDbDataAdapter provided for this that you can use wrapped around your existing SqlDataAdapter.

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.



来源:https://stackoverflow.com/questions/10824852/how-to-hook-up-sqldataadapter-to-profile-db-operations-with-mvc-mini-profiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!