使用MiniProfier分析DB2连接

时间:2016-06-01 17:11:57

标签: ado.net db2 miniprofiler

我试图将MiniProfiler添加到我的DB2连接中。以下是我的简化代码。

<div class="col-xs-12 col-sm-6 col-md-6">
    <div class="form-group">
        <input type="text" name="Address1" id="Address1" runat="server" class="form-control input-lg address" placeholder="Full Address" maxlength="50" tabindex="2" value="" >
    </div>
</div>

我的问题发生在将探查器分配给DB2Command的Connection属性的最后一行。我收到以下错误。

无法转换类型&#39; StackExchange.Profiling.Data.ProfiledDbConnection&#39;键入&#39; IBM.Data.DB2.DB2Connection&#39; 我尝试了几种不同的铸造思路,但没有任何结果。

2 个答案:

答案 0 :(得分:0)

DB2Command.Connection属性属于DB2Connection类型(正如错误消息有用地告诉您)。请尝试DbConnection

c.DbConnection = profiler

More in the manual

答案 1 :(得分:0)

我认为你会倒退。您正在为ProfiledDbConnection类分配连接(看似正确,based on the docs在MiniProfiler网站上)。

但是,您正在创建特定于DB2的命令对象,并尝试将ProfiledDbConnection类分配给连接对象。

我认为您要做的是调用profiler.CreateDbCommand(),这将创建一个ProfiledDbCommand对象,该对象使用“隐藏”下的DB2Command类。