Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:04:42+00:00 2026-06-01T11:04:42+00:00

I use EF 4.2 code first in my mvc3 project. miniprofiler works fine (sql

  • 0

I use EF 4.2 code first in my mvc3 project.

miniprofiler works fine (sql + mvc), but I’ve got an issue with async tasks.

I perform ’em this way (is this method ok? I feel a bit uneasy with this new DatabaseContext())

public static void PerformAsycAction(this User user, Action<User> action)
{
   ThreadPool.QueueUserWorkItem(_ =>
   {
     var context = new DatabaseContext();
     MiniProfilerEF.Initialize();
     var consistantUser = context.Set<User>().Get(user.Id);
     action(consistantUser);
     context.SaveChanges();
   });
}

I’ve got proper line in Application_Start:

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

The excpetion is thrown during the first operation with db in action(consistantUser);
here is the trace:

at MvcMiniProfiler.MiniProfiler.AddSqlTiming(SqlTiming stats) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\MiniProfiler.cs:line 274
at MvcMiniProfiler.SqlTiming..ctor(DbCommand command, ExecuteType type, MiniProfiler profiler) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\SqlTiming.cs:line 137
at MvcMiniProfiler.SqlProfiler.ExecuteStartImpl(DbCommand command, ExecuteType type) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\SqlProfiler.cs:line 39
at MvcMiniProfiler.SqlProfilerExtensions.ExecuteStart(SqlProfiler sqlProfiler, DbCommand command, ExecuteType type) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\SqlProfiler.cs:line 93
at MvcMiniProfiler.MiniProfiler.MvcMiniProfiler.Data.IDbProfiler.ExecuteStart(DbCommand profiledDbCommand, ExecuteType executeType) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\MiniProfiler.IDbProfiler.cs:line 14
at MvcMiniProfiler.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\Data\ProfiledDbCommand.cs:line 158
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

what am I doing wrong?
Any help will be appreciated.

EDIT: I tried to initialize MiniProfiler (MiniProfilerEF.Initialize();) again, in the thread where backgroung task is performd (before initiating DatabaseContext), and there is another exception now:

Unable to cast object of type ‘MvcMiniProfiler.Data.EFProfiledDbConnection’ to type ‘System.Data.SqlClient.SqlConnection

In fact, it’s not neccessary to profile the queries in the background thread, but it crashes the whole thread, so the application doesn’t work properly, and I have to disavble the whole profiler. Is there a way to disable it for that, background, thread to prevent it from crashing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:04:43+00:00Added an answer on June 1, 2026 at 11:04 am

    The code breaks when it tries to access your connection string because the connection string is an Entity Framework style connection string.

    When passing connection string to the mini-profiler you have to extract the actual connection string from the EF connection string.

    EntityConnection connection = 
        new EntityConnection(ConfigurationManager
                       .ConnectionStrings["ConnectionStringName"].ConnectionString));
    
    string connectionString = connection.StoreConnection.ConnectionString;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use MVC3 with the Entity framework with Code First, but
I have an MVC3 project I created using the Code First paradigm and it
I have .NET MVC 3 project where I use sql membership provider and entity
I'm running into an issue with Entity Framework code-first in MVC3. I'm hitting this
So I am learning MVC3 and EF4. I tried the code first method but
I'm working on a wiki project. MVC3 + EF4 Code First. All classes from
I use this code to determine checkbox width and height: var chk = $('input[type=checkbox]:first');
First the requirements: By management requirements, I can't use open source code. I need
I want to use code beside files for my views in my ASP.NET MVC
What DB Management Systems does EF 4.2 Code First support? I'd like to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.