如何在 Visual Studio 2010 中连接到 MySQL 5.1?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/901049/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:19:47  来源:igfitidea点击:

How do I connect to MySQL 5.1 in Visual Studio 2010?

mysqlvisual-studio-2010

提问by jake

Does any one know how to connect to MySQL5.1 with Visual Studio 2010?

有谁知道如何使用Visual Studio 2010连接到MySQL5.1 ?

I have already tried the MySQL Connector/ODBCroute and it got me really nasty results. The table rows were all listed as a view in the views section and nothing at all was listed in the tables or procedures folder.

我已经尝试过MySQL 连接器/ODBC路由,它给我带来了非常糟糕的结果。表行都被列为视图部分中的视图,表或过程文件夹中根本没有列出任何内容。

采纳答案by Christian Payne

To get the Entity Frame working with VS2010, I had to do the following:

为了让实体框架与 VS2010 一起工作,我必须执行以下操作:

  1. This only worked with Mysql .net Connector v6.3.1 (alpha). Previous versions ignored VS 2010 (click Development Releases)
  2. I had to rename my Framework\v1.1.4322\CONFIG folder. Otherwise the install will fail. Rename it back when finished
  1. 这仅适用于 Mysql .net Connector v6.3.1 (alpha)。以前的版本忽略了 VS 2010(单击开发版本)
  2. 我不得不重命名我的 Framework\v1.1.4322\CONFIG 文件夹。否则安装将失败。完成后重命名

(I've blogged about this here)

(我已经在这里写了关于这个的博客)

Update6.3.2 is in betaand I can confirm this works. (I didn't need to rename the framework folder)

更新6.3.2 处于测试阶段,我可以确认它有效。(我不需要重命名框架文件夹)

回答by Luiscencio

this seems to solve the issue

这似乎解决了这个问题

UPDATED LINK TO LATEST RELEASE THANKS @Christian Payne

最新版本的更新链接感谢@Christian Payne

Update: looks like there is already a non-beta!!!!

更新:看起来已经有一个非测试版!!!!

http://www.mysql.com/downloads/connector/net/

http://www.mysql.com/downloads/connector/net/

回答by ricp

As someone else suggests..

正如别人建议的那样..

http://dev.mysql.com/downloads/mirror.php?id=382641

http://dev.mysql.com/downloads/mirror.php?id=382641

..fixes the problem.

..解决了问题。

I had v6.2.3 installed after I had vs2010 installed and the MySQL driver was not shown in the list of the Database Connect dialog. I wrongly assumed I should use the .NET ODBC drivers instead and it caused all sorts of problems. Although I could easily connect to the DB using codebehind, the server explorer wouldn't connect to the DB.

我在安装了 vs2010 之后安装了 v6.2.3,并且 MySQL 驱动程序没有显示在数据库连接对话框的列表中。我错误地认为我应该使用 .NET ODBC 驱动程序,这导致了各种各样的问题。虽然我可以使用代码隐藏轻松连接到数据库,但服务器资源管理器不会连接到数据库。

Luckily after uninstalling 6.2.3 and installing 6.3.0 (from the link above) the MySQL driver was added to VS2010, and I was able to connect to the database and see it in my server explorer.

幸运的是,在卸载 6.2.3 并安装 6.3.0(来自上面的链接)后,MySQL 驱动程序被添加到 VS2010,并且我能够连接到数据库并在我的服务器资源管理器中看到它。

回答by Al Dass

I was able to get this to work by doing the following:

我能够通过执行以下操作来使其工作:

My Environment:

我的环境:

  • Development Box -- Win7 64bit, VS2010 Pro
  • Deployment Box -- Win2k8 svr with IIS7 running ASP.NET .Net 2.0/3.0/3.5 sp which is hosted at DiscountAsp.Net (Note: DiscountAsp.Net does not provide a MySQL DB when running on a Win2k8 svr, I'm using a MySQL DB that I connect to elsewhere on the InterWebs)
  • 开发箱 -- Win7 64bit, VS2010 Pro
  • 部署箱——带有 IIS7 的 Win2k8 svr 运行 ASP.NET .Net 2.0/3.0/3.5 sp,托管在 DiscountAsp.Net(注意:DiscountAsp.Net 在 Win2k8 svr 上运行时不提供 MySQL DB,我正在使用我连接到 InterWeb 上其他地方的 MySQL 数据库)

Steps I took:

我采取的步骤:

  1. Installed MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d
  2. Ref'd the .Net 2.0 version of the MySQL assembly in my ASP.NET MVC2 Web project set to target .Net 3.5 (the path for the MySQL assemblies I used was C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v2.0)
  3. I ref'd all 3 of the MySQL assemblies (MySql.Data.dll, MySql.Data.Entity.dll & MySql.Web.dll)
  4. I marked each of those assemblies as "Copy Local=True" in my project (a.k.a bin deployment)
  5. Added a MySQL DB connection string to my Project (using the MySQL provider)
  6. Added an ADO.NET Entity Data Model to my project in VS2010 using the connections string
  7. VS2010 took about 30 secs to chew thru my MySQL DB schema but then provided me with a beautiful GUI interface to tweak my MVC Models
  8. Used the DB Entities in my MVC controllers
  9. Deployed the app to my hosted server at DiscountAsp.Net
  1. 已安装 MySql.Data,版本=6.3.6.0,文化=中性,PublicKeyToken=c5687fc88969c44d
  2. 在我的 ASP.NET MVC2 Web 项目中引用 .Net 2.0 版本的 MySQL 程序集设置为目标 .Net 3.5(我使用的 MySQL 程序集的路径是 C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v2.0)
  3. 我引用了所有 3 个 MySQL 程序集(MySql.Data.dll、MySql.Data.Entity.dll 和 MySql.Web.dll)
  4. 我在我的项目(又名 bin 部署)中将每个程序集标记为“Copy Local=True”
  5. 向我的项目添加了 MySQL 数据库连接字符串(使用 MySQL 提供程序)
  6. 在 VS2010 中使用连接字符串向我的项目添加了 ADO.NET 实体数据模型
  7. VS2010 花了大约 30 秒的时间来处理我的 MySQL 数据库架构,但随后为我提供了一个漂亮的 GUI 界面来调整我的 MVC 模型
  8. 在我的 MVC 控制器中使用了数据库实体
  9. 将应用程序部署到我在 DiscountAsp.Net 上的托管服务器

It works like a charm :)

它就像一个魅力:)

回答by Jason Short

Microsoft Visual Studio 2010 Beta 2 is busted for DDEXproviders. They are auto promoting a VS 2008 assembly from 9.0 to 10.0 and it fails. The failure has to do with the fact that a .NET 2 assembly cannot load a .NET 4 assembly.

Microsoft Visual Studio 2010 Beta 2 已被DDEX提供程序破坏。他们正在自动将 VS 2008 程序集从 9.0 升级到 10.0,但它失败了。失败与 .NET 2 程序集无法加载 .NET 4 程序集这一事实有关。

This worked in beta 1, so it is something they broke.

这在 beta 1 中有效,所以这是他们破坏的东西。

I even went back and tried the reference DDEX provider from the SDK. It won't load in VS 2010 beta 2 either. That tells me they have something that needs to be fixed.

我什至回去尝试了 SDK 中的参考 DDEX 提供程序。它也不会在 VS 2010 beta 2 中加载。这告诉我他们有一些需要修复的东西。

When is the next beta?

下一个测试版是什么时候?

回答by Frans Bouma

Erm... through code? Or do you mean the server explorer add-in? Have you tried the latest (albeit GPL-ed) connector version for .NET from Mysql themselves? Again, it's GPL-ed so be aware of the consequences of using that for your own software.

嗯...通过代码?或者你的意思是服务器资源管理器加载项?您是否尝试过 Mysql 自己为 .NET 提供的最新(尽管是 GPL 版本)连接器版本?同样,它是 GPL 版的,因此请注意将其用于您自己的软件的后果。