Trouble getting mvc mini profiler to work with EF 4.2

623 Views Asked by At

I've scoured through stack overflow posts but no luck thus far. I've started a new MVC 3 project that uses Entity framework 4.2. I used nuget to install packages MiniProfiler, MiniProfiler.MVC3, and MiniProfiler.EF (MiniProfiler.EF was also added to my domain layer). Without profiling entity framework, everything works fine. When I profile EF by uncommenting the line MiniProfilerEF.Initialize();, I get the error:

A provider factory for the specified store connection of type 'MvcMiniProfiler.Data.EFProfiledDbConnection' could not be discovered. The registered provider factories and all provider factories in the assembly where 'MvcMiniProfiler.Data.EFProfiledDbConnection' is defined were searched for a factory that would produce a matching connection.

I tried get the latest source code as I read the update for EF 4.1 required it. Now, when I run the project I get the error:

Unable to determine the provider name for connection of type 'MvcMiniProfiler.Data.EFProfiledDbConnection'.

The documentation I've gone through is a little confusing as I can't tell what is new and what is old. From this post it seems I need to modify anything in my web.config. Is there another step I'm missing? Thanks for the help.

2

There are 2 best solutions below

0
On

You should put MiniProfilerEF.Initialize(); line before any access to database:

protected void Application_Start()
{
       MiniProfilerEF.Initialize();

       // Start access database from here ...
       // For example call MyDbContext.Database.Exists();
}
0
On

Do you have this entry in your Web.config file?

  <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.EntityFramework, Version=1.9.1.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
    </DbProviderFactories>
  </system.data>