question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Cannot change the connection string on an open connection` from UseMySql

See original GitHub issue

Steps 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:open
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
lauxjpncommented, Nov 23, 2022
Message: 
System.InvalidOperationException : Cannot change the connection string on an open connection.

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 to InvalidOperationException back in 2017 and we missed it.

0reactions
lauxjpncommented, Dec 14, 2022

We keep this open until the backport is merged as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An error occurred using the connection to database '' on ...
The connection string was wrong, fixed it but error still showed. Solution: Recycle the app pool. Changing the .json file doesn't restart de ......
Read more >
Not able to configure connection string in ASP.net MVC ...
A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider.
Read more >
How to Connect to MySQL from .NET Core
A typical connection string for MySQL is: Server=YOURSERVER;User ID=YOURUSERID;Password=YOURPASSWORD;Database=YOURDATABASE.
Read more >
7.1 Entity Framework 6 Support
Edit the configuration sections in the app.config file to add the connection string and the Connector/NET provider. <connectionStrings> ...
Read more >
MySQL connection strings - ConnectionStrings.com
Use this one to specify which character set to use to encode queries sent to the server. Server=myServerAddress;Database=myDataBase;Uid=myUsername; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found