ylax
ylax

Reputation: 386

Provider not found in config or invalid error

I am using EF 6.0 in conjunction with MySql. I built my entity model with EF's model builder wizard and have made no custom edits to my app's generated config file. My application works fine on my computer, but when I try to install it on any other machine, I get two errors:

Error 1: "The specified store provider could not be found in the configuration or is invalid"
Error 2: "The specified named connection could not be found in the configuration, is not valid with the specified EntityClient, or is not valid".

I imagine that error 2 might go away if I solve error 1. I don't know anything about config files, so I've posted the content of the auto generated app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="prismatic_dbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db&quot;" providerName="System.Data.EntityClient" />
    <add name="prismatic_dbPrivileges" connectionString="metadata=res://*/PMConfigPrivilegesModel.csdl|res://*/PMConfigPrivilegesModel.ssdl|res://*/PMConfigPrivilegesModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
     </defaultConnectionFactory>   
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
   </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
       </dependentAssembly>
     </assemblyBinding>
  </runtime>
</configuration>

I noticed that the providers start tag has a blue squiggly line under it. Below is also the content of the auto generated packages.config (not sure what this one is for):

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.0.1" targetFramework="net45" />
</packages>

In this one, the packages start tag has a blue squiggly line under it.

Upvotes: 1

Views: 6329

Answers (1)

ylax
ylax

Reputation: 386

Pawel, your blog was my 'jumping off' point. I would have marked your comment as an 'answer' if it had been posted as one. Instead, I am 'answering' my own question... Thanks for your help, though.

In order to fix my issue:

1) I rolled back to EF5.
2) I rolled back to MySql Connector 5.6
3) I made to following edit, thanks to Pawel's advice:

 <providers>
      <provider invariantName="MySql.Data.MySqlClient"
            type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
 </providers>

By default, this text, for some reason, referenced SqlServer. I found some feeds online that indicated this might be a bug.

4) I added the following to the < configuration > section:

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider"
           invariant="MySql.Data.MySqlClient"
           description=".Net Framework Data Provider for MySQL"
           type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>

My final app.config file reads as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="prismatic_dbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db&quot;" providerName="MySql.Data.MySqlClient" />
    <add name="prismatic_dbPrivileges" connectionString="metadata=res://*/PMConfigPrivilegesModel.csdl|res://*/PMConfigPrivilegesModel.ssdl|res://*/PMConfigPrivilegesModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db&quot;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySQL Data Provider"
       invariant="MySql.Data.MySqlClient"
       description=".Net Framework Data Provider for MySQL"
       type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

  <entityFramework>
     <providers>
      <provider invariantName="MySql.Data.MySqlClient"
            type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
    </providers>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity">
      <parameters>
        <parameter value="v11.0" />
      </parameters>      
    </defaultConnectionFactory>

  </entityFramework>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
       </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I couldn't say definitively if it was necessary to roll back EF and MySql Connector. I will be attempting to move back to the latest versions of both soon. I will post my results when I do. Also, if anyone else has had similar issues and have successfully resolved them using the latest versions of connector and EF (at the current time, these are EF6 and MySql Connector 5.7), please post your results. Thanks, guys!

Upvotes: 1

Related Questions