Mvc-Mini-Profiler v1.7 on EF 4.1 Code-First project does not process SQL

I installed the MiniProfiler.MVC3 - 1.7 package in my project yesterday. The controller and profile profiling work fine, but I'm very interested in the fact that this is SQL profiling. I could not get this to work. I am using EF Code First with a SQL 2008 database.

I followed all the suggestions in this post.

mvcminiprofiler-on-ef-4-1-code-first-project-doesnt-profile-sql

In miniprofiler.cs, I have a SQL connection setup like ...

var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["CMDBMVC3"].ConnectionString); 

Connection of my Web.config db ...

  <add name="CMDBMVC3" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI; AttachDBFilename=|DataDirectory|CMDB_MVC3.mdf;Initial Catalog=CMDB_MVC3;Trusted_Connection=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> 

If I put a breakpoint on the mini profiler line, it indicates the correct db connection. I'm not sure what else to do at this point. I would appreciate any guidance on how to work with SQL profiling.

+4
source share
1 answer

First, I use the EF code and the mini profiler in my context constructor. I create a new factory connection and pass it to the ProfiledDbConnectionFactory method, this returns a profiled connection, which can then be set as the DefaultConnectionFactory context.

 public MyConext() { var factory = new ConnectionFactory(); var profiled = new MvcMiniProfiler.Data.ProfiledDbConnectionFactory(factory); Database.DefaultConnectionFactory = profiled; } 

Facotry connection just returns a new sql connection

 public class ConnectionFactory :IDbConnectionFactory { public DbConnection CreateConnection() { var cnn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["SomeConnection"].ToString()); return cnn; } 

You also need to add ProfiledDBProvider to the web configuration file. Make sure the version number is correct for you.

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

This works fine for me in both MVC and asp.net webforms using the Miniprofiler nuget package. I also checked out the new MVC version of nuget, which automatically configures profiling as part of a global action filter.

0
source

All Articles