简体   繁体   English

共享主机+实体框架+ MySQL =数据提供程序错误?

[英]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. 我正在尝试使用ADO.NET实体框架连接到MySQL。 (Visual Studio 2010, .NET 4.0) I created a web project and another class library project to serve as my DAL. (Visual Studio 2010,.NET 4.0)我创建了一个Web项目和另一个类库项目作为我的DAL。 On my local machine, I have no problems, and I have also tried running with Medium trust. 在我的本地机器上,我没有问题,我也尝试使用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. 我已经通过多种方式调整了web.config:我已经在连接字符串中显式调用了程序集,我使用了通配符映射,我添加了对MySQL dll的引用等。


<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. 我和他们的支持人员(他们不是开发人员)谈过,但是他们说安装了MySQL连接器并且在GAC中。 I tried to use the DbProviderFactories section in my web.config, like the following: 我尝试在web.config中使用DbProviderFactories部分,如下所示:

<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. 我尝试强烈签署我的DAL项目,而不是使用DAL,只是在Web项目中创建.edmx,一切都无济于事。 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). 我在我的应用程序中遇到了一个非常类似的问题,我在MySQL数据库使用MySQL连接器,SQL Server数据库使用实体框架(两个独立的连接,一个项目)。 The MySQL.Data.Entity DLL seems to fight with the entity framework. MySQL.Data.Entity DLL似乎与实体框架作斗争。 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. 最后出于绝望,我刚刚删除了我的bin和obj文件夹并重新编译。 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? 如果将mysql dll放在bin文件夹中会发生什么? Alternatively, try to remove the version restriction on the mysql dll, they may not have that exact version loaded on their servers. 或者,尝试删除mysql DLL上的版本限制,他们可能没有在他们的服务器上加载那个确切的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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