Unable to pass an object of type "MvcMiniProfiler.Data.EFProfiledDbConnection" to enter "System.Data.SqlClient.SqlConnection"

Cannot pass an object of type "MvcMiniProfiler.Data.EFProfiledDbConnection" to enter "System.Data.SqlClient.SqlConnection".

I try to switch to MvcMiniProfiler 1.9.0, and I keep getting this when I call MiniProfilerEF.Initialize (). I deleted the system.data configuration section. I do not know what I am doing wrong. I followed the steps on the site, but maybe I missed something?

I use EF code at the beginning of 4.1, and I pass the name of my connection string to the constructor to create my datacontext.

Web activator

using Project.Web.App_Start; using WebActivator; [assembly: PreApplicationStartMethod(typeof(MiniProfiler), "Start")] namespace Project.Web.App_Start { public class MiniProfiler { public static void Start() { if (Eco.Environment.IsDevelopment) { MiniProfilerEF.Initialize(); } } } } 

StructureMap Registry:

 using Project.Domain.Repositories; using StructureMap.Configuration.DSL; namespace Project.Web.DependencyResolution.Registries { public class RepositoriesRegistry : Registry { public RepositoriesRegistry() { For<IProjectDataContext>().HybridHttpOrThreadLocalScoped().Use(() => new ProjectDataContext(Eco.Database.Name)); } } } 

DataContext constructor:

  public ProjectDataContext(string nameOrConnectionString) : base(nameOrConnectionString) { Active = new Active(this); } 

I deleted the system.data dataproviders fron my config, as the documentation says that I only need to call MiniProfilerEF.Initialize ().

** Update

Earlier in 1.7 MvcMiniProfiler I had to set the Database.DefaultConnectionFactory property, but I removed it. The .DefaultConnectionFactory database always returns as SqlConnectionFactory, shouldn't it be ProfiledConnectionFactory or something like that?

+7
source share
5 answers

I saw this error. It drove me nuts, but I finally figured it out. My problem had nothing to do with web.config , assemblers, Initialize_42 or Initialize(false) hacks or something else.

Here where I made a mistake ...

I turned on the automatic application of such migrations:

App_Start:

 Database.SetInitializer( new MigrateDatabaseToLatestVersion<DataContext, Migrations.Configuration>() ); 

Migration / Configuration.cs:

 internal sealed class Configuration : DbMigrationsConfiguration<Path.To.DataContext> { public Configuration() { AutomaticMigrationsEnabled = true; } } 

And this is called through WebActivator as follows:

 [assembly: WebActivator.PreApplicationStartMethod( typeof(service_tracker_mvc.App_Start.DatabaseInitializer), "Start")] 

I accidentally discovered that disabling this process led to the work of the profiler. The problem with how this happens is that this initialization process is too early. This usually happens during Application_Start (unless you use this fancy WebActivator stuff), so I changed it to PostStart . Now it works:

  ▼▼▼▼ [assembly: WebActivator.PostApplicationStartMethod( typeof(service_tracker_mvc.App_Start.DatabaseInitializer), "Start")] 
+2
source

I made a mistake by adding MiniProfiler.EF instead of MiniProfiler.EF6. Removing MiniProfiler.EF and replacing it with the EF6 version fixed my problem.

+2
source

see stack overflow.

This is caused by performing database operations before initializing miniprofiler, setting a breakpoint in the counter structure for your db context, and the other in the line MiniProfilerEF.Initialize(); and processing prior to initialization.

+1
source

The problem that I see here is that ProjectDataContext encapsulates some data context in the "Active" property, which cannot be found by the MvcProfiler proxy.

Moreover, EFProfiledDbConnection is actually a child of DbConnection, but not a child of SqlConnection. This is done in terms of abstraction for using different Db providers such as MySql, Postgres, etc. Please try to look at all the variables in the code, they should be DbConnection, but not SqlConnection (this is the MsSql provider).

0
source

I had the same problem and decided to fix it to upgrade to Glimpse: http://getglimpse.com/ . In my opinion, this is much better than a mini profiler, easy to use, complete, etc.

0
source

All Articles