如何实例化一个 Profiled DataAdapter 以与 MVC MINI PROFILER 一起使用?

发布于 2024-11-27 19:30:51 字数 751 浏览 5 评论 0原文

所有 Command 对象都没有 Fill 方法,但在以前的方法中,我可以实例化一个新的 OracleDataAdapter。如何实例化 Profiled DataAdapter 来使用 MVC MINI PROFILER 分析我的数据库活动?

我所需要的只是将 Fill 命令与 MVC mini Profiler 的配置连接一起使用。

[更新]

我认为很多人以前一定已经这样做过,除非他们使用实体框架,它工作得很好而且很简单。在我的例子中,查询被动态加载到数据表中,并且实体无法被映射,因为应用程序不知道它。

通过分析连接创建命令后最大的问题是将其设置为无法实例化的 DataAdapter。

[更新] 更多参考:

None of the Command objects have Fill methods, but in the former way I was doing I could instantiate a new OracleDataAdapter. How could I instantiate a Profiled DataAdapter to profile my database activity with MVC MINI PROFILER?

All I need is to use the Fill command with the profiled connection of MVC mini Profiler.

[UPDATE]

I think many must have done that before, unless they are using Entity Framework, which works nice and easy. In my case the query is loaded dynamically into a Datatable, and the entity cannot be mapped, since it is unknown by the application.

The biggest problem after creating a command by the profiled connection is to set it to a DataAdapter which cannot be instantiated.

[UPDATE] Further References:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-12-04 19:30:51

根据罗里

“为此提供了一个类 ProfiledDbDataAdapter,您可以使用它来包装现有的 SqlDataAdapter。”

通过这个提示,您可以编写一些像这样的代码

public DbConnection _dbConnection;
private DbCommand _dbCommand;
private DbDataAdapter _dbDataAdapter;

public DataSet GetResultByProcWithSingleParam(string procName, SqlParameter sqlParams)
        {
            try
            {
                _dbCommand = _dbConnection.CreateCommand();
                _dbCommand.CommandType = CommandType.StoredProcedure;
                _dbCommand.Parameters.Add(sqlParams);
                _dbCommand.CommandText = procName;
                _dbConnection.Open();
                _dbCommand.ExecuteNonQuery();
                _dbDataAdapter = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter();
                _dbDataAdapter = new ProfiledDbDataAdapter(_dbDataAdapter);
                _dbDataAdapter.SelectCommand = _dbCommand;
                _ds = new DataSet();
                _dbDataAdapter.Fill(_ds);
                _dbConnection.Close();
                return _ds;
            }
            catch (Exception ex)
            {

                throw;
            }

        } 

,并且该代码的命名空间是:

using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;

我希望它能够工作。就我而言,它运行成功。

According to Rory

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

By this hint, you can write some code like this

public DbConnection _dbConnection;
private DbCommand _dbCommand;
private DbDataAdapter _dbDataAdapter;

public DataSet GetResultByProcWithSingleParam(string procName, SqlParameter sqlParams)
        {
            try
            {
                _dbCommand = _dbConnection.CreateCommand();
                _dbCommand.CommandType = CommandType.StoredProcedure;
                _dbCommand.Parameters.Add(sqlParams);
                _dbCommand.CommandText = procName;
                _dbConnection.Open();
                _dbCommand.ExecuteNonQuery();
                _dbDataAdapter = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter();
                _dbDataAdapter = new ProfiledDbDataAdapter(_dbDataAdapter);
                _dbDataAdapter.SelectCommand = _dbCommand;
                _ds = new DataSet();
                _dbDataAdapter.Fill(_ds);
                _dbConnection.Close();
                return _ds;
            }
            catch (Exception ex)
            {

                throw;
            }

        } 

And namespaces for this code are:

using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;

I hope it will work. In my case, it is working successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文