Bug #108954 "No database selected" error for MySql with EF Core 6
Submitted: 1 Nov 2022 13:50 Modified: 4 Mar 14:08
Reporter: Eric Finch Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version: OS:Windows
Assigned to: CPU Architecture:Any
Tags: Entity Framework Core

[1 Nov 2022 13:50] Eric Finch
Description:
When I use MySql.EntityFrameworkCore 6.0.7, if I do not specify a database in my connection string, I get a "No database selected" exception when using the entities to select data with Linq statements.  Oddly, When I use SaveChanges to insert records into the database, I do not get any errors.  When I use MySql.EntityFrameworkCore 3.1.27, I can do all operations without any errors.  Additionally, in both versions, I can use the underlying MySqlConnection to query the database, without specifying the database in the connection string.  This seems like a bug with the .Net 6 versions of MySql.EntityFrameworkCore, since it was working fine in the old versions, plus my entities have the schema defined, so I should not have to supply that in the connection string.

Stack Trace:  MySqlStream.ReadPacket() NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) Driver.NextResult(Int32 statementId, Boolean force) MySqlDataReader.NextResult() MySqlCommand.ExecuteReader(CommandBehavior behavior) MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) DbCommand.ExecuteReader() RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) Enumerator.InitializeReader(Enumerator enumerator) <>c.b__19_0(DbContext _, Enumerator enumerator) MySQLExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) Enumerator.MoveNext() List1.ctor(IEnumerable1 collection) Enumerable.ToList[TSource](IEnumerable`1 source)

How to repeat:
Use MySQL entities to select data from a table, without database being in the connection string.  This will work in version 3.1.27, but will throw an exception in version 6.0.7.

Suggested fix:
Allow all Entity Framework operations without specifying database in the connection string, since it is effectively already specified as the schema in the entity declaration.
[14 Nov 2022 6:58] MySQL Verification Team
Hello Eric Finch,

Thank you for the bug report.
Verified as described.

Regards,
Ashwini Patil
[22 Aug 2023 12:17] Eric Finch
Did this issue ever get addressed?  I just grabbed MySql.EntityFrameworkCore 6.0.16, and it is still exhibiting the behavior.
[4 Mar 14:08] Eric Finch
The year is now 2024 and I still see this bug in MySql.EntityFrameworkCore 6.0.25.  Am I the only person who is impacted by this?