Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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>
                How we are suppose to change at runtime from mssql to mysql or mysql to mssql? link. Please let me know.
– Narendra Singh Rathore
                May 22, 2017 at 2:32
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.