Combining Entity Framework 6 with MySQL and SQL Server databases

Hey everyone, I’m working on a project that needs to use both SQL Server and MySQL databases. I’ve got MySQL working fine with EF6, but I’m running into issues when I try to add a second DbContext for SQL Server. When I try to run any commands on the SQL Server context, I get an error saying the provider didn’t return a ProviderManifestToken string, and it mentions something about not being able to connect to MySQL hosts. I’ve looked into it and it seems like the MySqlEFConfiguration is overriding all the config settings. Even when I set the provider name to System.Data.SqlClient, the connection still shows up as MySql.Data.MySqlClient.MySqlConnection. I’ve tried separating things into different class libraries and messing with the order of initialization, but no luck so far. Has anyone run into this before or know how to get EF6 to play nice with both MySQL and SQL Server in the same project? I’m pretty stuck at this point and would appreciate any ideas!

have you tried using separate connection strings for each context? i had a similar problem and fixed it by explicitly setting the providerName in the connection string for SQL Server:

make sure youre not using any global mysql config that might override this. hope this helps!

I’ve encountered a similar issue when working with multiple database providers in EF6. One approach that worked for me was to explicitly specify the provider factory for each context. In your SQL Server DbContext, try adding this to the constructor:

((IObjectContextAdapter)this).ObjectContext.Connection.ConnectionString = "your_connection_string";
((IObjectContextAdapter)this).ObjectContext.Connection.StoreProviderFactory = System.Data.SqlClient.SqlClientFactory.Instance;

This should override any global provider settings. Also, ensure you’re not using any global configuration that might be affecting all contexts. Each context should have its own configuration.

If that doesn’t work, you might need to look into using separate app domains for each context, though that’s a more complex solution. Let me know if you need more details on implementation.