【问题标题】:MvcMiniProfiler not working with Oracle's Connection ObjectMvc MiniProfiler 不适用于 Oracle 连接对象
【发布时间】:2011-10-16 03:57:40
【问题描述】:

以下代码的最后一行触发了异常: OracleConnection conn = new OracleConnection(getConnectionString());

        // A SqlConnection, SqliteConnection ... or whatever          
        // wrap the connection with a profiling connection that tracks timings      
        var cnn = MvcMiniProfiler.Data.ProfiledDbConnection.Get(conn, MiniProfiler.Current); 
        OracleCommand cmd = new OracleCommand(sql, (OracleConnection) cnn);

即:

Unable to cast object of type 'MvcMiniProfiler.Data.ProfiledDbConnection' to type 'Oracle.DataAccess.Client.OracleConnection'.

我正在使用 Oracle 数据提供程序。用于 oracle 的 devArt 也是如此。

谢谢:)

【问题讨论】:

    标签: c# oracle database-connection mvc-mini-profiler dbconnection


    【解决方案1】:

    那是因为你需要把它当作一个抽象连接,并在基类/接口上使用现有的CreateCommandCreateParameter等方法。或者,如果您想避免这种混淆 - “dapper”(或任何其他 ADO.NET 实用程序层)之类的东西会为您省去很多麻烦。

    这里的原因是分析器“装饰”连接,这反过来意味着它必须装饰其他对象并在正确的时间展开它们。这确实是可能以这种方式分析 ADO.NET

    【讨论】:

    • 谢谢!但是可以使用 FIll 命令吗?在 MVC MiniProfiler 之前,应用程序正在填充数据表。基本命令对象不提供填充方法,到目前为止,我无法实例化适当的 DataAdapter。如果不可能,我将不得不做出巨大的改变,将数据表(使用扩展属性)转换为数据读取器。
    • @ClayKaboom OracleCommand also 没有 Fill 方法 AFAIK...如果您使用的是 DataTable,那么这是 DataTable 或 aapter 的工作,不是吗?
    • 不,没有一个命令对象有 Fill 方法,但在前一种方式中,我可以实例化一个新的 OracleDataAdapter。如何实例化 Profiled DataAdapter?
    • @ClayKaboom 一个很好的问题;我现在正在调查。我有 DbProviderFactory,所以我可以获得 CreateDataAdapter - 但需要包装。正在努力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 2014-08-06
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多