Hoo*_*ody 12 c# mysql entity-framework
我在C#中编写了一个程序集来执行MySQL数据库的所有数据访问.我在C#winform桌面应用程序中成功使用了程序集(已编译的dll).但它仅适用于安装了"MySQL Connector Net 6.4.4"的PC.
我试图在我的asp.net网站项目中使用相同的程序集.首先我得到一个关于缺少连接字符串的错误.通过将MySQL连接字符串添加到web.config文件可以轻松解决这个问题.我现在得到这个错误(下面列出的堆栈跟踪),我已经尝试将以下dll添加到我的bin文件夹来解决它但它不起作用.
MySql.Data.dll
MySql.Data.Entity.dll
MySql.Web.dll
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown.
---> 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
Run Code Online (Sandbox Code Playgroud)
Lad*_*nka 35
但它仅适用于安装了"MySQL Connector Net 6.4.4"的PC.
这是否意味着您尝试在未安装提供程序的计算机上运行代码?在这种情况下,您还必须在配置文件中注册提供程序,因为安装会将其添加到machine.config,如果您没有安装它,则提供程序当前未注册.
尝试将此添加到您的web.config文件中:
<system.data>
<DbProviderFactories>
<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.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Run Code Online (Sandbox Code Playgroud)
我发现在使用独立的.NET连接器6.6.5安装程序时也遇到了这个问题.
要解决此问题,只需卸载独立的.NET连接器安装程序,然后安装mysql-community-installer,此安装程序允许您向MySQL添加/删除功能,其中一个功能是具有Entity Framework支持的.NET连接器.
一旦使用此连接器,所有MySQL EF问题都将消失.
| 归档时间: |
|
| 查看次数: |
41611 次 |
| 最近记录: |