我有1.6版的MvcMiniProfiler引用(通过Nuget),并按照项目主页
http://code.google.com/p/mvc-mini-profiler/所述设置所有内容.
我在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>
(项目主页版本= 1.5.0.0 – NuGet软件包已更新)
我在Global.asax中有以下代码(和连接字符串也在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项目主页上关注相关问题,并完全陷入困境.
解决方法
这一次让我很久很久以来一直陷入困境.看来连接字符串命名约定优先于Database.DefaultConnectionFactory.
可以尝试重新命名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);