无法从 Visual Studio 2015 连接到 mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32037178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot connect to mysql from visual studio 2015
提问by ditoslav
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.
所以我已经花了大约 2 天的时间来解决这个问题。我已经成功地在我的工作电脑上修复了这个问题,但无法在我的家用电脑上运行。我已经阅读了大约十几篇 SO 文章和 oracle 论坛文章等等,但仍然无法正常工作。
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.
我有 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 个文件并将它们复制到整个 fkin计算机。我已经像到处一样粘贴了它。vs2013 私有程序集,我什至没有提到的包文件夹,我认为一些 vs2015 文件夹。我搜索了 Mysql.Data 并将这些文件粘贴到结果出现的每个文件夹中。我已经重建了大约 100-200 次解决方案,并且已经哭了至少 20 分钟。
What do I have to do to get my new ADO.Net Entity Data Model generated?
我该怎么做才能生成新的 ADO.Net 实体数据模型?
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?
我一直得到这个愚蠢的图像,我真的完全不知道下一步该怎么做。我只是想编码,但每次我开始做某事时,我都会在无法正常工作的工具上浪费时间。我真的必须在记事本中编码才能确定某些东西不起作用是我的错吗?
This is my app.Config file. I do not have anything else in my project.
这是我的 app.Config 文件。我的项目中没有任何其他内容。
<?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>
回答by Samko
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.
为了让 VS 2015 连接到 MySql,您需要使用更高版本的 MySql 库。虽然这似乎是一个非常简单的答案,但老实说,我在此过程中遇到了几个问题。考虑到这一点,我将写出在让 EF 与 MySql 和 VS2015 一起工作方面一直对我有用的 1 个过程。因此,事不宜迟,以下是我为使其发挥作用而采取的步骤。
1) Make sure the MySql connector installation is updated
1) 确保更新了 MySql 连接器安装
2) Create your web project
2)创建你的网络项目
3) Open Nuget
3) 打开 Nuget
4) Install Entity Framework
4) 安装实体框架
5) Search for MySql
5)搜索MySql
6) Install MySql.Data
6)安装MySql.Data
7) Install MySql.Data.Entity
7) 安装 MySql.Data.Entity
8) Install MySql.Data.Entities
8) 安装 MySql.Data.Entities
9) Install MySql.Web
9) 安装 MySql.Web
10) Go to the references for the project and delete MySql.Data.Entity.EF6
10)转到项目的引用并删除MySql.Data.Entity.EF6
11) Check the versions of the MySql.Data and MySql.Web libraries. If they are under 6.9.6 delete them as well
11) 检查 MySql.Data 和 MySql.Web 库的版本。如果它们低于 6.9.6 也删除它们
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)
12) 通过浏览到您的 .NET 框架版本的 mysql 连接器的安装位置(我的是 C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5)添加一个新的参考抓取 MySql.Data.Entity.EF6.dll(我的版本是 6.9.6,当我们稍后更改 web.config 时请记住这一点)
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.
13) 如果其他库也是旧版本,请通过浏览到解决方案中的包文件夹并从各自文件夹中获取文件来添加对它们的引用。我通常不必这样做。
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.)
14) 现在需要编辑 Web.config。第一步是用此代码替换实体框架部分(将版本号更改为您当前的版本。请注意,我几周前在网上找到了这个片段,没有原始链接。我向原文道歉此信息的海报。)
<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) Make sure your DbProviderFactories section matches
15) 确保您的 DbProviderFactories 部分匹配
<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) Save and build
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. 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.
PS 如果在所有这些之后您通过向导并且在它向您显示数据库中的表以从中创建实体之前它就消失了,那么这可能是我在此过程中遇到的三个问题之一。无法联系数据库服务器。用户没有所需的数据库权限。MySql.Data.Entity.EF6 的错误版本被添加为参考或 web.config 中的版本号错误。如果我从我的解决方案的包目录中获取这个文件,我经常会遇到这个 aborted-wizard-with-no-error-message 问题。每次从 MySql 安装目录中获取它对我来说都很好。
回答by Dejan Rajic
It works for me. I have Visual Studio 2015, and just installed latest version of connector: http://dev.mysql.com/downloads/windows/visualstudio/
这个对我有用。我有 Visual Studio 2015,刚刚安装了最新版本的连接器:http: //dev.mysql.com/downloads/windows/visualstudio/
Read this more carefully: http://dev.mysql.com/doc/relnotes/mysql-for-visual-studio/en/visual-studio-news-1-2-4.html
更仔细地阅读:http: //dev.mysql.com/doc/relnotes/mysql-for-visual-studio/en/visual-studio-news-1-2-4.html
They mention that version of "Microsoft ASP.NET MVC" could be a problem. Wrong is that they say VS2015 ships with version 5, but I have version 4 installed with VS2015 Enterprise final.
他们提到“Microsoft ASP.NET MVC”的版本可能是一个问题。错误的是,他们说 VS2015 附带版本 5,但我安装了 VS2015 Enterprise final 的版本 4。
回答by Jay247
Tried this and it didn't work for me. What eventually worked was making sure I had the right driver. I run a 64bit Windows 7 computer. I eventually had to install the 32bit version of the MySQL ODBC connector/driver and used the following connection string "Provider=MSDASQL; Driver={MySQL ODBC 5.3 ANSI Driver}; Server=localhost; Database=xxxx; User=xxxx; password=xxxx; Option=3;" and that solved it. tested it on a new project without making all the above changes, and it worked just fine. This post was super helpful in explaining this: https://support.microsoft.com/en-us/kb/942976. Hope this saves someone a lot of time
试过这个,它对我不起作用。最终起作用的是确保我有合适的驱动程序。我运行的是 64 位 Windows 7 计算机。我最终不得不安装 32 位版本的 MySQL ODBC 连接器/驱动程序并使用以下连接字符串“Provider=MSDASQL;Driver={MySQL ODBC 5.3 ANSI Driver};Server=localhost;Database=xxxx;User=xxxx;password= xxxx;选项=3;" 这解决了它。在没有进行上述所有更改的情况下在一个新项目上对其进行了测试,并且效果很好。这篇文章对解释这个非常有帮助:https: //support.microsoft.com/en-us/kb/942976。希望这可以为某人节省很多时间
回答by Jon Hallam
install the package from this site. http://dev.mysql.com/downloads/windows/visualstudio/in the Development release tab.
从此站点安装软件包。http://dev.mysql.com/downloads/windows/visualstudio/在开发版本选项卡中。
I stopped Visual Studio.. I installed. WAITED.. Seams to take for ever. Visual studio will be running in the background.
我停止了 Visual Studio.. 我安装了。等待.. 接缝永远。Visual Studio 将在后台运行。
Wait till completed.
等到完成。
reopen Visual Studio. boom back in play!
重新打开 Visual Studio。热潮回归!
Good luck !
祝你好运 !
回答by JSM
For VS2015 I removed all version installed and through the MySql Installer - Community. I selected Customize Installation and selected MySQL Connectors to install: 1. MySql for Visual Studio 2) MySQl ConnectorNet.
I added references: MySql.Data y MySql.Data.Entity.EF5 both in C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\
Recompiled the project And When creating de ADO.Net Object the famous MySql data provider was shown! A warning was displayed about Entity Frame Versions, I just clicked Next And worked![enter image description here][1]
对于 VS2015,我通过 MySql 安装程序 - 社区删除了所有已安装的版本。我选择了自定义安装并选择了要安装的 MySQL 连接器: 1. MySql for Visual Studio 2) MySQl ConnectorNet。
我在 C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\ 中添加了引用:MySql.Data y MySql.Data.Entity.EF5
重新编译项目并在创建 de ADO.Net Object 时显示了著名的 MySql 数据提供程序!显示了关于实体框架版本的警告,我只是单击了下一步并成功了![在此处输入图像描述][1]