Visual Studio 2017 未在连接列表中显示 MySQL [英] Visual Studio 2017 not showing MySQL in connection list

查看:40
本文介绍了Visual Studio 2017 未在连接列表中显示 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Visual Studio 2017 Professional".我无法让项目认识到 MySQL 是一个可用的数据库选项.当我创建一个新模型时,MySQL 没有出现在可能的连接列表中.我知道有很多关于这个主题的 SO 问题和其他网页,因为我已经尝试了很多建议.每一个在原因和解决方案上都有微妙的不同.似乎没有一个解决方案适合我.

I am using "Visual Studio 2017 Professional". I can not get a project to recognize that MySQL is an available DB option. MySQL does not show up in the list of possible connections when I create a new model. I know that there are tons of SO questions and other web pages on this topic because I have tried a lot of the suggestions. Each is subtlety different in cause and solution. None of the solutions seem to work for me.

我在 VS 2017 和 2015 中尝试了以下操作,结果相同.我有旧版本的 VS 可用,但向后推进似乎不值得.我还尝试在必要时使用社区安装程序"和独立的 msi 安装最新和旧版本的 MySQL.我回到了 MySQL 6.10 之前的最新"版本.

I have tried the following with VS 2017 and 2015 with the same results. I have older versions of VS available but it didn't seem worthwhile to march that far back. I have also tried installing the latest and older versions of MySQL both with the "Community Installer" and the standalone msi's when necessary. I went back to the "latest" pre-6.10 version of MySQL.

首先,当我注意到 nuget 有可用的 MySQL 包更新时,这个传奇开始于上周.我应用了它们,然后使用社区安装程序升级已安装的 MySQL 组件.nuget 更改确实适用.但是,社区安装程序无法为 VS 卸载 MySQL.系统安装程序无法卸载它.重新启动和电源循环没有任何作用.

To begin, this saga started last week when I noticed that nuget had MySQL package updates available. I applied them and then went to upgrade the installed MySQL componants with the Community Installer. The nuget changes did apply. The Community Installer could not uninstall MySQL for VS though. The system installer could not uninstall it. Rebooting and power-cycling did nothing.

根据我们当地技术支持人员的建议,我使用了第三方卸载程序,结果证明它比我们想象的更具攻击性.它似乎随机踩踏了注册表,擦除了它发现的任何内容.长话短说(呃),我最终让我的机器重新成像.所以,我有一个全新的 Windows 安装.

On the advice of our local tech support folks I used a third party uninstaller that turned out to be more aggressive than we imagined. It seems to have randomly stommped across the registry erasing whatever it found. Long story short(er), I ended up having my machine reimaged. So, I have a fresh windows install.

鉴于全新的 Win10 平台,我安装了我通常使用的各种东西,包括我通常使用的 VS 版本.我安装了最新的社区 MySQL 安装程序.我进行了自定义"MySQL 安装,因为我不需要此设备或结构上的服务器或许多其他东西.

Given the fresh Win10 platform, I installed the various things I normally use including the VS versions I typically use. I installed the latest Community MySQL installer. I did a "custom" MySQL install because I don't need a server on this device or fabric or many other things.

我完成了所有内容的基本重新安装,然后重新启动以确保安全.我启动了 VS 2017 并使用最新的 .Net (4.6.1) 版本创建了一个新的 Web 应用程序.我应用了 nuget 更新并添加了 EntityFramework 和 MySQL.Data.然后我尝试创建一个新的代码优先"模型.

I finished the basic reinstall of everything then rebooted just to be sure. I started VS 2017 and created a new web app with the latest available version of .Net (4.6.1). I applied nuget updates and added EntityFramework and MySQL.Data. I then tried to create a new "code first" model.

我可以达到要求我创建连接的程度.当我单击该按钮时,可用数据库提供程序的列表仅显示 MS SQL.

I can get to the point where I am asked to create a connection. When I click the button the list of available DB providers only shows MS SQL.

我看过那些说要在 Web.config 中添加行的文章,我也看过 MySQL .Net Connector 文档也说过同样的话.我可以在 Web.config 中看到 MySQL 条目,但在创建连接时它们不显示.

I have seen the articles that say to add lines to Web.config and I have seen the MySQL .Net Connector docs that say the same things. I can see the MySQL entries in Web.config but they do not show up when creating a connection.

奇怪的是我可以去Tools ->连接到数据库 并查看我的机器知道的关于包括 MySQL 的每个数据库类型.我可以创建连接字符串并且它可以工作.我可以在服务器资源管理器"中看到数据库,但它不能用于代码.

An oddity is that I can go to Tools -> Connect to Database and see EVERY DB type my machine knows about including MySQL. I can create the connection string and it works. I can see the DB in "Server Explorer` but that doesn't make it available to code.

好的,我已经一遍又一遍地按照上述步骤进行操作,包括降级 EntityFramework 版本和 MySQL 版本.

Ok, I have followed the above steps over and over including downgrading the version of EntityFramework as well as the MySQL version.

我最近的尝试让我回到了最新版本的 VS 和 MySQL.Web.config 文件的相关(我认为)部分如下.请注意,defaultConnectionFactory 条目是 LocalDbConnectionFactory.我已将其更改为 SqlConnectionFactory ,但没有任何区别.我还更改了提供程序的顺序和主要块的顺序.

My most recent attempt has me back to the latest version of VS and MySQL. The relevant (I think) section of the Web.config file follow. Note the defaultConnectionFactory entry is LocalDbConnectionFactory. I have changed that to SqlConnectionFactory but it has not made a difference. I have also changed the order of the providers and the order of the major blocks.

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient"
                type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient"
                type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider>
    </providers>
</entityFramework>
<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient"
           name="MySQL Data Provider"
           type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

编辑

我目前的印象是 VS 2017 是一个无法使用的混乱,伪装成已发布的可销售产品.我已经回到了2015年.

My current impression is that VS 2017 is an unusable mess masquerading as a released, salable product. I have returned to 2015.

我更接近于在 2015 年使用它.我安装了用于 VS 和 .Net 的最新 MySQL 项目.我已将 nuget EF 包降级到 6.0,将 MySql 包降级到 6.8.8.

I have come closer to getting this to work in 2015. I have the latest MySQL items for VS and .Net installed. I have downgraded the nuget EF package to 6.0 and the MySql packages to 6.8.8.

在我现在所说的过去的美好时光"中,我可以通过选择 Models 文件夹向 MVC 项目添加新模型;选择添加新项目";选择ADO.Net模型;选择一个连接选项(MySQL);输入连接信息;选择 DB First 或 Code First,然后等待脚手架的乐趣结束.

In, what I am now calling, "the good old days" I could add a new model to an MVC project by selecting the Models folder; selecting "Add New Item"; choosing ADO.Net model; select a connection option (MySQL); enter the connection info; choose DB First or Code First and wait for the scaffolding fun to finish.

现在,我得先去Tools ->连接到数据库 并创建一个到 MySql 数据库的连接.如果我不这样做,我以后就不会在可能的连接列表中看到 MySQL.然后我清理并构建项目.接下来我尝试像上面那样创建模型.不,我可以看到 MySQL 连接选项,我可以输入数据库凭据并测试连接.

Now, I have to first go to Tools -> Connect to Database and create a conenction to a MySql DB. If I do not do this I will not see MySQL in the list of possible connections later. I then clean and build the project. Next i try to create the model as above. Noe I can see the MySQL connection option and I can enter the DB creds and test the connection.

下一步是选择 DB First 或 Code First.在任何一种情况下,单击下一步"按钮都会闪烁一个空白弹出窗口,然后消失.未显示任何错误且未建立任何连接.

The next step is to choose DB First or Code First. In either case, clicking the "next" button flashes a blank pop-up that then vanishes. No errors are shown and no connection is made.

过去从来没有这么难过.

It was never this hard in the past.

此时我已经在 2015 和 2017 年尝试了很多不同的 MySQL 和 EF 版本.如果有魔法组合请告诉我.

I have tried a lot of different MySQL and EF versions on 2015 and 2017 at this point. If there is a magic combo please tell me.

推荐答案

我已经为此奋斗了两个星期.我最终找到了适合我的版本组合.以下内容适用于两周前我的 Win10 桌面的原始重新映像.在开始处理MySql之前,所有补丁都被应用到系统软件上.

I have been fighting this fight for two weeks. I FINALLY found a combo of versions that works for me. The following was applied to a pristine re-image of my Win10 desktop two weeks ago. All patches were applied to system software before starting to deal with MySql.

就在今天早上,我重读了这个帖子(MySql 论坛)中的帖子:https://forums.mysql.com/read.php?174,659102,660369#msg-660369

Just this morning I re-read the post in this thread (MySql Forums): https://forums.mysql.com/read.php?174,659102,660369#msg-660369

我以为我之前已经尝试过这些建议,但我一定是搞砸了其中一个版本.我认为海报的基本策略是合理的.就我而言,我卸载了所有本地 MySql 部件和安装程序.

I thought that I had tried those suggestions before but I must have messed up one of the versions. I think that poster's basic strategy is sound. In my case I uninstalled all local MySql parts and the installer.

我下载了用于 Visual Studio 的 MySQL - 最新开发 版本(在撰写本文时为 2.0.5 msi)并安装了它.

I downloaded MySQL for Visual Studio - the Latest Development version (2.0.5 msi as of this writing) and installed that.

我找到了 .Net 连接器的旧版本并安装了 6.9.11

I found the OLD versions of the .Net Connector and installed 6.9.11

在 VS 2017 中,我使用 .Net 4.6.1 创建了一个虚拟项目.

In VS 2017 I created a dummy project using .Net 4.6.1.

我应用了待处理的 VS 更新.

I applied pending VS updates.

我构建了这个项目.

我转到项目 -> 管理 Nuget 包"并将 EntityFramework 安装/降级到 6.0.

I went to "Project -> Manage Nuget Packages" and installed / downgraded EntityFramework to 6.0.

我在 6.9.11 版本中安装了 MySql.Data、MySql.Data.Entity 和 MySql.Web

I installed MySql.Data, MySql.Data.Entity and MySql.Web all at version 6.9.11

我清理并构建了项目,然后尝试从 MySql 数据库中添加一个新的代码优先"模型......它奏效了!

I cleaned and built the project then tried to add a new "Code First" model from a MySql DB... IT WORKED!

这篇关于Visual Studio 2017 未在连接列表中显示 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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