使用EF部署应用程序

时间:2013-11-17 17:38:38

标签: mysql entity-framework app-config

我在使用EF4.2作为ORM和MySQL作为DB部署应用程序时出现问题。我将MySQL.Data(v.6.7.4)和MySQL.Data.Entity(v.6.7.4.1)添加到项目中。我的app.config有以下结构:

<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="Settings.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="SUDBContext" connectionString="metadata=res://*/Model.ORM.SUDB.csdl|res://*/Model.ORM.SUDB.ssdl|res://*/Model.ORM.SUDB.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;{0}&quot;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <userSettings>
    <Settings.Settings>
      <setting name="RequestTimeout" serializeAs="String">
        <value>3000</value>
      </setting>
      <setting name="FindOrderByBarcodeUrl" serializeAs="String">
        <value>http://developmachine.babadu.ru/exchange/restservice/getorderinfobybarcode.php?barcode={0}</value>
      </setting>
      <setting name="ChangeOrderStateUrl" serializeAs="String">
        <value>http://developmachine.babadu.ru/exchange/restservice/changeordershippingstatus.php?id={0}&amp;status={1}</value>
      </setting>
      <setting name="ConnectionString" serializeAs="String">
        <value>server=localhost;user id=root;password=qwerty123;persist security info=True;database=sudb</value>
      </setting>
      <setting name="DefaultPrinter" serializeAs="String">
        <value />
      </setting>
      <setting name="IsDirectPrint" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="FindOrderByNumberUrl" serializeAs="String">
        <value>http://babadu.ru/exchange/restservice/getorderinfobyid.php?id={0}</value>
      </setting>
    </Settings.Settings>
  </userSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.7.4.0" newVersion="6.7.4.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

当我尝试启动应用程序并在开发人员计算机上从数据库进行查询时,一切都很好。当我尝试在客户机上启动它时,我得到了错误:“在配置中找不到指定的商店提供商,或者无效。” 我做错了什么?

P.S。 MySQL .NetConnector v6.7.4和.NetFramework v.4已经安装在客户端'机器上

1 个答案:

答案 0 :(得分:0)

我做到了!感谢文章MySQL Forum我找到了错误的原因。我做了什么:

  1. 注册新提供商 MySQL数据提供商
  2. 添加标记删除不变
  3. 在连接字符串标记中将providerName设置为 System.Data.EntityClient
  4. 直接在连接字符串中将提供程序设置为 MySql.Data.MySqlClient
  5. 修改后的App.config具有以下结构:

    <configuration>
      ...
      <connectionStrings>
        <add name="SUDBContext" connectionString="metadata=res://*/Model.ORM.SUDB.csdl|res://*/Model.ORM.SUDB.ssdl|res://*/Model.ORM.SUDB.msl;provider=MySql.Data.MySqlClient;provider connection string='{0}'" providerName="System.Data.EntityClient"/>
      </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"/>
          </DbProviderFactories>
      </system.data>
    

    ...