EF 4.1 Code-First 项目上的 MvcMiniProfiler 不分析 SQL [英] MvcMiniProfiler on EF 4.1 Code-First project doesn't profile SQL
问题描述
我引用了 MvcMiniProfiler 的 1.6 版(通过 Nuget),并且按照 http://code.google.com/p/mvc-mini-profiler/.
I have version 1.6 of the MvcMiniProfiler referenced (via Nuget) and have set everything up as described on the project homepage at http://code.google.com/p/mvc-mini-profiler/.
我在 Web.config 中有以下代码:
I have the following code in the Web.config:
<system.data>
<DbProviderFactories>
<remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" />
<add name="MvcMiniProfiler.Data.ProfiledDbProvider" invariant="MvcMiniProfiler.Data.ProfiledDbProvider" description="MvcMiniProfiler.Data.ProfiledDbProvider" type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler, Version=1.6.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
</DbProviderFactories>
</system.data>
(项目主页的 Version=1.5.0.0 - NuGet 包已经更新)
(The project homepage has Version=1.5.0.0 - the NuGet package has since been updated)
我在 Global.asax 中有以下代码(以及也在 Web.config 中定义的连接字符串):
I have the following code in the Global.asax (and connection string also defined in Web.config):
protected void Application_Start()
{
Log.Info("ReCoupon has started.");
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["ReCouponContext"].ConnectionString);
var profiled = new MvcMiniProfiler.Data.ProfiledDbConnectionFactory(factory);
Database.DefaultConnectionFactory = profiled;
Database.SetInitializer(new ReCouponContextInitializer());
}
探查器工作得很好,只是我无法用它来分析 SQL.我正在使用 SQL Server 2008 Express.我一直在关注 Google Code 项目主页上的相关问题,但完全卡住了.
The profiler works great except that I can't get it to profile SQL. I am using SQL Server 2008 Express. I've been following the related issues on the Google Code project homepage and am totally stuck.
推荐答案
这个也让我难住了很久.连接字符串命名约定似乎优先于 Database.DefaultConnectionFactory.
This one had me stumped for a long time too. It appears that the connection string naming convention takes precedence over Database.DefaultConnectionFactory.
您可以尝试重命名 web.config 中的连接字符串吗?
Could you try renaming the connection string in the web.config?
来自
<connectionStrings>
<add name="ReCouponContext" connectionString="..." />
</connectionStrings>
到
<connectionStrings>
<add name="ReCoupon" connectionString="..." />
</connectionStrings>
然后改变
var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["ReCouponContext"].ConnectionString);
到
var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["ReCoupon"].ConnectionString);
这篇关于EF 4.1 Code-First 项目上的 MvcMiniProfiler 不分析 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!