title: Upgrading to MvcMiniProfiler 1.9 from 1.7 .NET MVC3 and EF Code First
body: <p>Today I've dropped back into a project that I haven't been working with for the past month or so. I had this project configured using MiniProfiler 1.7 and all was well in the world. It profiled my DB calls and the view performance as well.</p>
  
  <p>I decided to upgrade to 1.9 and I've run into a few speed bumps. Now, I've worked through most of the issues at this point. The only thing that seems "wrong" is DB profiling. I'm getting dropped a yellow screen of death with the following error:</p>
  
  <pre><code>A null was returned after calling the 'get_ProviderFactory' method on a store 
  provider instance of type 'MvcMiniProfiler.Data.ProfiledDbConnection'. 
  The store provider might not be functioning correctly.
  </code></pre>
  
  <p>For reference, let me show you how I had miniprofiler setup in 1.7 with MVC3 and EF 4.1 Code First.</p>
  
  <p>web.config</p>
  
  <pre><code>  &lt;system.data&gt;
  &lt;DbProviderFactories&gt;
    &lt;remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" /&gt;
    &lt;add name="MvcMiniProfiler.Data.ProfiledDbProvider" 
         invariant="MvcMiniProfiler.Data.ProfiledDbProvider" 
         description="MvcMiniProfiler.Data.ProfiledDbProvider" 
         type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler, Version=1.7.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" /&gt;
  &lt;/DbProviderFactories&gt;
  </code></pre>
  
  <p></p>
  
  <p>Global.asax handled most everything from there. I'll list the relevant Application_Start() code that worked prior that doesn't now.</p>
  
  <pre><code>#region MVC Mini Profiler related database profiling config/setup
  
          //This line makes SQL Formatting smarter so you can copy/paste 
          // from the profiler directly into Query Analyzer
          MiniProfiler.Settings.SqlFormatter = new SqlServerFormatter();
  
          var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
          var profiled = new ProfiledDbConnectionFactory(factory);
          Database.DefaultConnectionFactory = profiled;
  
  #endregion
  </code></pre>
  
  <p>With the last step being in my context hooking in the profiled connection:</p>
  
  <pre><code>public class Database : DbContext
  {
      public Database()
          : base(GetProfilerConnection(), true)
      {}
  
      private static DbConnection GetProfilerConnection()
      {
          return
              ProfiledDbConnection.Get(
                  new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ConnectionString));
      }
  }
  </code></pre>
  
  <p>Fast forward to today and I've reworked things to use the MVC3 minprofiler nuget package and the EF miniprofiler NuGet package, but I'm lost on how to get DB profiling working again.</p>
  
  <p>I've modified my web.config to the following which <em>seemed</em> to be what was required but ReSharper isn't happy first off.</p>
  
  <pre><code>  &lt;system.data&gt;
  &lt;DbProviderFactories&gt;
    &lt;remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" /&gt;
    &lt;add name="MvcMiniProfiler.Data.ProfiledDbProvider" invariant="MvcMiniProfiler.Data.ProfiledDbProvider"
         description="MvcMiniProfiler.Data.ProfiledDbProvider"
         type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler.EntityFramework, Version=1.9.1.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" /&gt;
  &lt;/DbProviderFactories&gt;
  </code></pre>
  
  <p></p>
  
  <p><img src="https://i.stack.imgur.com/owFcU.png" alt="enter image description here"></p>
  
  <p>Not quite sure what I'm missing here. Do I even need this anymore with a call to MiniProfilerEF.Initialize();? Some documentation and suggestions seem to indicate you don't even need this anymore.</p>
  
  <p>The bigger problem is how to setup DB Profiling in 1.9.</p>
  
  <p>The relevant code that I had prior in Global.asax has now been moved into MiniProfiler.cs in the App_Start folder. I figured the setup would have been the same but that doesn't appear to be the case. </p>
  
  <p>I want to do this (perhaps because this is just what I'm familiar with in 1.7)</p>
  
  <pre><code>//TODO: To profile a standard DbConnection: 
          var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
          var profiled = new ProfiledDbConnectionFactory(factory);
          Database.DefaultConnectionFactory = profiled;
  </code></pre>
  
  <p>This doesn't seem to work any longer. I've also noted that it seems I should be using EFProfiledDbConnection now instead of just ProfiledDbConnection? Is this correct?</p>
  
  <p>How do I go about configuring DB profiling with this model? I'm digging high and low through documentation, but there's so much information with the old way mixed in with the new way and I'm having a hard time separating what the "correct" way is today.</p>