我将EF 6.0与MySql结合使用。我使用EF的模型构建器向导构建了我的实体模型,并且没有对我的应用程序生成的配置文件进行自定义编辑。我的应用程序在我的计算机上工作正常,但当我尝试在任何其他计算机上安装它时,我得到两个错误:
错误1:“在配置中找不到指定的商店提供商或无效”
错误2:“在配置中找不到指定的命名连接,对指定的EntityClient无效,或者无效”。
我想如果我解决错误1,错误2可能会消失。我对配置文件一无所知,所以我发布了自动生成的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="server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db"" 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="server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db"" 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>
我注意到providers
开始标记下面有一条蓝色波浪线。以下是自动生成的packages.config
的内容(不确定这是什么):
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.0.1" targetFramework="net45" />
</packages>
在这一个中,packages
开始标记下面有一条蓝色波浪线。
答案 0 :(得分:1)
帕维尔,你的博客是我的“跳跃点”。如果已将评论标记为“答案”,我会将其标记为“答案”。相反,我正在“回答”我自己的问题......感谢你的帮助。
为了解决我的问题:
1)我回到了EF5
2)我回滚到MySql Connector 5.6
3)由于Pawel的建议,我做了以下编辑:
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
</providers>
默认情况下,由于某种原因,此文本引用了SqlServer。我在网上发现了一些表明这可能是个错误的信息。
4)我将以下内容添加到&lt;配置&gt;部分:
<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>
我的最终app.config文件内容如下:
<?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="server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db"" 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="server=localhost;user id=pmuser;password=pmuser;persist security info=True;database=prismatic_db"" 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>
我无法肯定地说是否有必要回滚EF和MySql Connector。我将尽快回到最新版本。我会在发布时发布结果。此外,如果其他人遇到类似问题并使用最新版本的连接器和EF(目前这些是EF6和MySql Connector 5.7)成功解决了它们,请发布您的结果。谢谢,伙计们!