3

The below configuration works fine when I specify the connectionString name as a parameter to the base constructor. Because I want to be able to change the default provider later on without recompiling, I want to set it in my app.config instead, but I have no idea what to provide as type for defaultConnectionFactory.

 <connectionStrings>
 <add name="MySQL" providerName="MySql.Data.MySqlClient" connectionString="SERVER=localhost;DATABASE=abc;UID=root;PASSWORD=;" />
 </connectionStrings>
 <entityFramework>
 <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, EntityFramework"></defaultConnectionFactory>
 <providers>
 <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
 </providers>
 </entityFramework>

Exception:

Failed to set Database.DefaultConnectionFactory to an instance of the 'MySql.Data.Entity.MySqlConnectionFactory, EntityFramework' type as specified in the application configuration. See inner exception for details.

Inner exception (translated, VS is set to English but some messages are still in my language):

Could not load type "MySql.Data.Entity.MySqlConnectionFactory" in assembly "EntityFramework"

The documentation states that the assembly name follows after the colon, thus I also tried MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6, giving me this exception:

Format of the initialization string does not conform to specification starting at index 0.

I'm using EF6, MySql.Data & MySql.Data.Entity.EF6 6.8.3.0.

asked Feb 6, 2014 at 13:40

1 Answer 1

9

The name property of the connectionString must be the same as your context. This works fine:

 <connectionStrings>
 <add name="NAMEOFYOURCONTEXT" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=abc;Uid=root;Pwd='';" />
 </connectionStrings>
 <entityFramework>
 <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6"></defaultConnectionFactory>
 <providers>
 <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
 </providers>
 </entityFramework>
answered Feb 6, 2014 at 16:13
1
  • How we are suppose to change at runtime from mssql to mysql or mysql to mssql? link. Please let me know. Commented May 22, 2017 at 2:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.