Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
425 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...