无法从 Visual Studio 2015 连接到 mysql

所以我已经花了大约 2 天的时间尝试解决这个问题.我已经成功地在我的工作电脑上修复了这个问题,但无法在我的家用电脑上运行.我已经阅读了大约十几篇 SO 文章和 oracle 论坛文章等等,但仍然无法正常工作.

So I have already spent about 2 days trying fix this. I have succeeded in fixing this on my workplace pc and can't get it to work on my home pc. I have read about a dozen SO articles and oracle forums articles and whatnot but still it does not work.

我有用于 Visual Studio 的 1.2.4 msql,它应该是一个适用于 vs2015 的版本.我已经安装了 mysql 连接器 6.8.6 并首先尝试通过 nuget 将 mysql 添加到我的项目中,但是在找不到 6.8.6 版本之后(一个包有 6.8.3 和 6.9.7,然后又是其他东西)对于另一个...)我已经引用了我的 C:Program Files (x86)MySQLMySQL Connector Net 6.8.6Assembliesv4.5 并在那里获取了 4 个文件并将它们复制到整个 fkin计算机.我已经像到处一样粘贴了它.vs2013 私有程序集,我什至没有提到的包文件夹,我认为一些 vs2015 文件夹.我搜索了 Mysql.Data 并将这些文件粘贴到每个文件夹中.我已经重新构建了大约 100-200 次解决方案,并且哭了至少 20 分钟.

I have 1.2.4 msql for visual studio which is supposed to be a release which works on vs2015. I have installed mysql connector 6.8.6 and have first tried to add mysql to my project via nuget but after not being able to find a 6.8.6 version (there are 6.8.3 and 6.9.7 for one package and then again something else for the other...) I have referenced to my C:Program Files (x86)MySQLMySQL Connector Net 6.8.6Assembliesv4.5 and have taken the 4 files there and have copied them ove the whole fkin computer. I have pasted it like everywhere. The vs2013 private assembly, my packages folder which I do not even reference to anyway and I think some vs2015 folder. I have ran a search for Mysql.Data and have pasted these files in every folder that came up as a result. I have rebuilt the solution for about 100-200 times and have cried for at least 20 minutes.

我需要做什么才能生成新的 ADO.Net 实体数据模型?

What do I have to do to get my new ADO.Net Entity Data Model generated?

我不断收到这个愚蠢的图像,我真的完全不知道下一步该做什么.我只是想编码,但每次我开始做某事时,我都会在无法正常工作的工具上浪费时间.我真的必须在记事本中编写代码才能确定某些东西不起作用是我的错吗?

I keep getting this stupid image and I have really absolutely no idea what to do next. I just want to code but every time I start doing something I keep wasting days on tools not working. Do I really have to code in notepad so that I am sure it's my fault that something isn't working?

这是我的 app.Config 文件.我的项目中没有任何其他内容.

This is my app.Config file. I do not have anything else in my project.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v12.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <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.8.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.8.6.0" newVersion="6.8.6.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="KPlusConnectionString" connectionString="server=dito.ninja;user id=xxx;password=xxx;database=xxx" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

推荐答案

为了让 VS 2015 连接到 MySql,您需要使用更高版本的 MySql 库.虽然这似乎是一个非常简单的答案,但老实说,我在此过程中遇到了几个问题.考虑到这一点,我将写出就让 EF 与 MySql 和 VS2015 一起工作而言一直对我有用的 1 个过程.因此,事不宜迟,以下是我为使其发挥作用而采取的步骤.

In order for VS 2015 to connect to MySql you need to be using a later version of the MySql libraries. While that seems like a pretty simple answer, in all honesty I have run into several problems along the way. With that in mind I am going to write out the 1 process that has consistently worked for me as far as getting EF working with MySql and VS2015. So, without further ado, here are the steps I have been taking in order to get this to work.

1) 确保更新了 MySql 连接器安装

1) Make sure the MySql connector installation is updated

2) 创建您的网络项目

2) Create your web project

3) 打开 Nuget

3) Open Nuget

4) 安装实体框架

5) 搜索 MySql

5) Search for MySql

6) 安装 MySql.Data

6) Install MySql.Data

7) 安装 MySql.Data.Entity

7) Install MySql.Data.Entity

8) 安装 MySql.Data.Entities

8) Install MySql.Data.Entities

9) 安装 MySql.Web

9) Install MySql.Web

10) 转到项目的引用并删除 MySql.Data.Entity.EF6

10) Go to the references for the project and delete MySql.Data.Entity.EF6

11) 检查 MySql.Data 和 MySql.Web 库的版本.如果它们低于 6.9.6 也删除它们

11) Check the versions of the MySql.Data and MySql.Web libraries. If they are under 6.9.6 delete them as well

12) 通过浏览到您的 .NET 框架版本的 mysql 连接器的安装位置(我的是 C:Program Files (x86)MySQLConnector.NET 6.9Assembliesv4.5) 并抓取 MySql.Data.Entity.EF6.dll(我的版本是 6.9.6,稍后我们更改 web.config 时请记住这一点)

12) Add a new reference by browsing to the install location for the mysql connector for your version of the .NET framework (mine is C:Program Files (x86)MySQLConnector.NET 6.9Assembliesv4.5) and grabbing the MySql.Data.Entity.EF6.dll (my version is 6.9.6, keep that in mind when we change the web.config later)

13) 如果其他库也是旧版本,请通过浏览到解决方案中的包文件夹并从各自文件夹中获取文件来添加对它们的引用.我通常不需要这样做.

13) If the other libraries were also older versions, add references to them by browsing to the packages folder in your solution and grabbing the files from their respective folders. I do not normally have to do this.

14) 现在需要编辑 Web.config.第一步是用这段代码替换实体框架部分(将版本号更改为您当前的版本.请注意,我几周前在网上找到了这个片段,没有原始链接.我向原文道歉此信息的海报.)

14) Now the Web.config will need to be edited. The first step is to replace the entity framework section with this code (change the version number to your current version. Please note that I found this snippet on the web a couple weeks ago and do not have the original link. I apologize to the original poster of this information.)

<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</entityFramework>

15) 确保您的 DbProviderFactories 部分匹配

15) Make sure your DbProviderFactories section matches

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

16) 保存并构建

我不确定这些步骤中有多少是实际需要的,但在最终完成后,我不得不真正完成一些工作并且没有时间进一步缩小范围.希望这能让你动起来.

I am not sure how many of these steps are actually required but after finally getting it once I had to actually get some work done and didn’t have time to narrow things down further. Hopefully that gets you moving.

附言如果在所有这些之后您通过向导并且在它向您显示数据库中的表以从中创建实体之前它就消失了,那么这可能是我在此过程中遇到的三个问题之一.无法联系数据库服务器.用户没有所需的数据库权限.MySql.Data.Entity.EF6 的错误版本被添加为参考或 web.config 中的版本号错误.如果我从我的解决方案的包目录中获取这个文件,我经常会遇到这个 aborted-wizard-with-no-error-message 问题.每次从 MySql 安装目录中获取它对我来说都很好.

P.S. If after all of that you go through the wizard and it just disappears before it shows you the tables in the database to create entities from then it could be one of three problems I have run into along the way. The database server cannot be contacted. The user does not have the needed permissions on the database. The wrong version of MySql.Data.Entity.EF6 was added as a reference or the version number is wrong in the web.config. If I grab this file from the packages directory of my solution I often run into this aborted-wizard-with-no-error-message problem. Grabbing it from the MySql install directory has worked fine for me every time.

相关文章