简体   繁体   中英

Shared Hosting + Entity Framework + MySQL = Data Provider Errors?

long-time listener, first-time caller!

I'm trying to connect to MySQL using the ADO.NET Entity Framework. (Visual Studio 2010, .NET 4.0) I created a web project and another class library project to serve as my DAL. On my local machine, I have no problems, and I have also tried running with Medium trust. I'm able to fully control the db as expected.

When I deploy to my host (shared, medium trust) however, I keep getting errors. I have tweaked my web.config multiple ways: I've explicitly called my assembly in the connection string, I've used the wildcard mapping, I added references to the MySQL dll's, etc.


<connectionStrings>
    <add name="NamespaceContext" connectionString="metadata=res:// Namespace.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/DataModel.csdl|res:// Namespace.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/DataModel.ssdl|res:// Namespace.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/DataModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=myserver;User Id=user;database=thedatabase;password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient"/>
    <add name=" NamespaceContext " connectionString="metadata=res://*/;provider=MySql.Data.MySqlClient;provider connection string=&quot; server=myserver;User Id=user;database=thedatabase;password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient"/>
        <add name=" NamespaceContext " connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot; server=myserver;User Id=user;database=thedatabase;password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

The error I keep getting is:

System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. ---> 
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed. 
at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) 
at System.Data.EntityClient.EntityConnection.GetFactory(String providerString) 
--- End of inner exception stack trace --- 
at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at MyNamespace.Web.Html.TestPage.EntityFrameworkTestButton_Click(Object sender, EventArgs e)

I talked to their support guys (who aren't devs) but they said the MySQL connector is installed and in the GAC. I tried to use the DbProviderFactories section in my web.config, like the following:

<system.data>
    <DbProviderFactories>
      <clear/>
      <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, Version=6.3.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    </DbProviderFactories>
  </system.data>

I was hoping I could control this and reference the provider in my project. I then receive the following error:

System.Data.MetadataException: Schema specified is not valid. 
Errors: error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered. 
MySql.Data.Entity.Properties.SchemaDefinition-6.0.ssdl(4,9) : error 0169: All SSDL artifacts must target the same provider. The ProviderManifestToken '5' is different from '5.0' that was encountered earlier. 
error 0194: All artifacts loaded into an ItemCollection must have the same version.

(lots of the same error message was snipped for brevity)


I am at a complete loss. I tried strongly signing my DAL project, not using a DAL and just creating the .edmx in the web project, all to no avail. I could have sworn I got it working at some point, but perhaps I was delirious.

Sorry for the wall o' text. Can anyone help or shed some light?

Thanks!

I had a very similar problem in my application, where I was using the MySQL connector for a MySQL database and the Entity Framework for a SQL Server database (two separate connections, one project). The MySQL.Data.Entity DLL seems to fight with the entity framework. I didn't actually need it so I removed it... but the error persisted!

Finally out of desperation I just deleted my bin and obj folders and recompiled. Problem solved. I guess something was cached or hanging around in my folders, even after I ran a clean and rebuild. Something to try anyways if someone else runs into this.

What happens if you put the mysql dll in your bin folder? Alternatively, try to remove the version restriction on the mysql dll, they may not have that exact version loaded on their servers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM