`Cannot change the connection string on an open connection` from UseMySql
See original GitHub issueSteps to reproduce
Call UseMySql[TContext](DbContextOptionsBuilder`1 optionsBuilder, DbConnection connection, ServerVersion serverVersion, Action`1 mySqlOptionsAction)
with a MySqlConnector.MySqlConnection (Cannot change the connection string on an open connection) or MySqlDataAlias.MySql.Data.MySqlClient.MySqlConnection (Not allowed to change the ‘ConnectionString’ property while the connection (state=Open).) that was already open.
The issue
When I call UseMySql
, I get Cannot change the connection string on an open connection
or “Not allowed to change the ‘ConnectionString’ property while the connection (state=Open).) that was already open.”, depending on the connection type. This was working fine with Pomelo.EntityFrameworkCore.MySql 3.2.7, but is now an issue with 6.0.2.
Message:
System.InvalidOperationException : Cannot change the connection string on an open connection.
Stack Trace:
MySqlConnection.set_ConnectionString(String value) line 491
MySqlDbContextOptionsBuilderExtensions.UseMySql(DbContextOptionsBuilder optionsBuilder, DbConnection connection, ServerVersion serverVersion, Action`1 mySqlOptionsAction)
MySqlDbContextOptionsBuilderExtensions.UseMySql[TContext](DbContextOptionsBuilder`1 optionsBuilder, DbConnection connection, ServerVersion serverVersion, Action`1 mySqlOptionsAction)
Further technical details
MySQL version: 8 Operating system: Windows 10 Pomelo.EntityFrameworkCore.MySql version: 6.0.2
Issue Analytics
- State:
- Created a year ago
- Comments:7
That exception message is definitely unexpected. The one supposed to be thrown is:
https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blob/147559fcc81ec51020b142d1a0eb6c42dde8c82f/src/EFCore.MySql/Extensions/MySqlDbContextOptionsBuilderExtensions.cs#L179
Looks like the inner exception type thrown by MySqlConnector was change from
MySqlException
toInvalidOperationException
back in 2017 and we missed it.We keep this open until the backport is merged as well.