Pomelo.EntityFrameworkCore.MySql: "Cannot Open when State is Connecting."

I have noticed a unexpected behavior.

In my controller i do a simple _databaseContext.Users.FirstOrDefault(); which works as expected (returns my first user).

But if i put a breakpoint on this line and move the cursor over Users in order to look into the DbSet i receive a empty list. After that i resume the program and get a Exception “Cannot Open when State is Connecting.”

System.InvalidOperationException: Cannot Open when State is Connecting.
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

Any ideas?

Great work and thanks in advance!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

I got the same error recently, but in a different scenario. Might help to track down the cause. I opened two separate instances of DbContext from the same DbContextOptions instance. This caused both to use same connection and throw this error.