简体   繁体   English

如何为包含数据库连接器的程序集设置绝对路径? 带有实体框架4.1的MySQL Connector 6.4.3

[英]How do I set the absolute path for a assembly containing Database connector? MySQL Connector 6.4.3 with Entity Framework 4.1

Reason why: http://bugs.mysql.com/bug.php?id=61933 原因: http : //bugs.mysql.com/bug.php?id=61933

I recompiled the connector from source, incremented tit a version to 6.4.3.1, but now this (possibly) trivial question blocks me. 我从源头重新编译了连接器,将tit的版本增加到6.4.3.1,但是现在(可能)这个琐碎的问题阻止了我。

How do I set the full provider name in the connection string in app.config? 如何在app.config的连接字符串中设置完整的提供程序名称? I have the official 6.4.3 connector installed. 我已经安装了官方的6.4.3连接器。

The error I get is when I add a new entity data model, and select from an existing database. 我得到的错误是当我添加一个新的实体数据模型,并从一个现有的数据库中进行选择时。 This I traced to the above linked (silly) bug. 我跟踪到上面的链接(傻)错误。

I couldn't find a better title for this question. 对于这个问题,我找不到更好的标题。


Microsoft Visual Studio Microsoft Visual Studio

An error occurred while connecting to the database. 连接到数据库时发生错误。 The database might be unavailable. 该数据库可能不可用。 An exception of type 'System.Data.ProviderIncompatibleException' occurred. 发生类型为“ System.Data.ProviderIncompatibleException”的异常。 The error message is: 'The provider did not return a ProviderManifestToken string. 错误消息是:'提供程序未返回ProviderManifestToken字符串。

The inner exception caught was of type 'System.FormatException', with this error message: 'Input string was not in a correct format.'.'. 捕获的内部异常的类型为“ System.FormatException”,并显示以下错误消息:“输入字符串的格式不正确。”。

OK


Solution

  1. Download MySQL Connector/6.4.3 sources, and extract it. 下载MySQL Connector / 6.4.3源代码并将其解压缩。

  2. In the MySql.Data.Entity project, replace...: 在MySql.Data.Entity项目中,替换...:

  3. (ProviderServices.cs:188) With: double version = double.Parse(connection.ServerVersion.Substring(0, 3), System.Globalization.CultureInfo.InvariantCulture); (ProviderServices.cs:188)使用:双版本= double.Parse(connection.ServerVersion.Substring(0,3),System.Globalization.CultureInfo.InvariantCulture);

  4. (ProviderManifest.cs:73) With: double version = double.Parse(manifestToken, System.Globalization.CultureInfo.InvariantCulture); (ProviderManifest.cs:73)使用:double版本= double.Parse(manifestToken,System.Globalization.CultureInfo.InvariantCulture);

  5. Create a new sign key and name it ConnectorNet (same name as in the assemblyinfo.cs) 创建一个新的符号密钥并将其命名为ConnectorNet(与assemblyinfo.cs中的名称相同)

  6. Add .1 to the AssemblyVersion in AssemblyInfo.cs in the MySql.Data project, this 1 file is shared with the rest: [assembly: AssemblyVersion("6.4.3.1")] 在MySql.Data项目的AssemblyInfo.cs中的AssemblyVersion中添加.1,此1文件与其余文件共享:[assembly:AssemblyVersion(“ 6.4.3.1”)]

  7. Put Release as target configuration, you can also disable the .Tests projects from being built. 将“发布”作为目标配置,您也可以禁用.Tests项目。

  8. As admin, install them with gacutil. 以管理员身份使用gacutil安装它们。 Here you also get the public key token. 在这里,您还可以获得公钥令牌。

  9. Locate Machine.config note it is important to know what .NET fx you compiled the project(s) to use. 找到Machine.config,注意了解编译项目要使用的.NET fx非常重要。

  10. Search for DbProviderFactories, and comment out the existing MySQL Data Provider, copy it and replace in the duplicate entry, by adding the .1 in version and the public key token. 搜索DbProviderFactories,并注释掉现有的MySQL数据提供程序,将其复制并替换为重复项,方法是在版本中添加.1和公用密钥令牌。

<!-- 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.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" / -->

<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.3.1, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX" />

Connection string doesn't contain path to provider assembly. 连接字符串不包含提供程序集的路径。 Connection string's providerName is only reference to provider registered in system.data\\DbProviderFactories : 连接字符串的providerName仅引用在system.data\\DbProviderFactories注册的提供者:

<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, Version=6.4.3.1, Culture=neutral, PublicKeyToken=YourToken" />
</system.data>

The invariant from factory registration is what you reference in providerName of connection string. 工厂注册的invariant是您在连接字符串的providerName中引用的内容。 You can try to put your new connector assembly to your application directory or strongly name the assembly install it to GAC. 您可以尝试将新的连接器程序集放到您的应用程序目录中,或者使用强烈的名称将该程序集安装到GAC。

Simpler solution: use the official 6.4.3 installer. 更简单的解决方案:使用官方的6.4.3安装程序。

Go in your regional settings, change your decimal separator from ',' to '.' 进入您的区域设置,将小数点分隔符从“,”更改为“。”。 et voilà. 等。

It's enough while waiting for the 6.4.4 to ship. 等待6.4.4发布就足够了。

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

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