无法从Visual Studio 2015连接到MySQL [英] Cannot connect to mysql from visual studio 2015

查看:76
本文介绍了无法从Visual Studio 2015连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经花了大约2天的时间来解决此问题.我已成功在工作场所的PC上修复了此问题,但无法在家用PC上运行.我已经读了大约十二篇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)\ MySQL \ MySQL Connector Net 6.8.6 \ Assemblies \ v4.5,并已将其中的4个文件复制到整个文件中.电脑.我已经像到处粘贴它. vs2013私有程序集,我的packages文件夹,我什至都没有引用,我认为有些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)\MySQL\MySQL Connector Net 6.8.6\Assemblies\v4.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)创建您的Web项目

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 Framework版本的mysql连接器的安装位置来添加新引用(我的位置是C:\ Program Files(x86)\ MySQL \ Connector.NET 6.9 \ Assemblies \ v4. 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)\MySQL\Connector.NET 6.9\Assemblies\v4.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)如果其他库也是较旧的版本,请通过浏览到解决方案中的packages文件夹并从各自的文件夹中获取文件来添加对它们的引用.我通常不必这样做.

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.

P.S.如果所有这些都经过向导,并且在显示数据库中的表以创建实体之前它消失了,那么它可能是我在此过程中遇到的三个问题之一.无法联系数据库服务器.用户对数据库没有所需的权限.添加了错误的MySql.Data.Entity.EF6版本作为参考,或者在web.config中版本号错误.如果我从解决方案的packages目录中获取此文件,则我经常会遇到这个无错误消息的异常终止向导.每次都可以从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.

这篇关于无法从Visual Studio 2015连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆