代码之家  ›  专栏  ›  技术社区  ›  JohnB

如何连接到Visual Studio中的MySQL数据源

  •  32
  • JohnB  · 技术社区  · 15 年前

    我使用 mysql connector/net 通过引用程序集(mysql.data.dll)并将连接字符串传递给 mysql connection ,来连接到我的数据库。我喜欢这样,因为我不需要安装任何东西。

    在Visual Studio 2010中,是否有某种方法可以“选择数据源”,而不安装某些内容?

    如何让mysql选项(localhost)出现在这些列表中?或者我需要安装什么? < /P>

    (我不想使用odbc btw)

    “Add connection”from server explorer:

    实体数据模型向导: 通过引用程序集(mysql.data.dll)并将连接字符串传递给 MySqlConnection . 我喜欢这样,因为我不需要安装任何东西。

    在Visual Studio 2010中,是否有某种方法可以“选择数据源”,而不安装任何内容?

    如何让mysql选项(localhost)出现在这些列表中?或者我需要安装什么?

    (我不想使用odbc btw)

    从服务器资源管理器添加连接: alt text

    实体数据模型向导:

    10 回复  |  直到 8 年前
        1
  •  7
  •   Lucas    15 年前

    Visual Studio要求通过在安装期间在Windows注册表中添加某些项来注册DDEX提供程序(数据设计器扩展性)( HKLM\SOFTWARE\Microsoft\VisualStudio\{version}\DataProviders )见 DDEX Provider Registration 有关详细信息,请参阅msdn。

        2
  •  29
  •   Jon Black    15 年前

    安装此处找到的mysql.net连接器 http://dev.mysql.com/downloads/connector/net/

    alt text

        3
  •  26
  •   Memet Olsen    8 年前

    “从6.7版开始,connector/net将不再包含用于Visual Studio集成的MySQL。该功能现在可在单独的名为mysql for Visual Studio的产品中使用,该产品使用mysql installer for Windows提供。“

    来源: http://dev.mysql.com/downloads/connector/net/6.6.html

        4
  •  10
  •   Benjamin W.    10 年前

    经过大量的搜索和尝试,我终于找到了:

    1. 卸载连接器

    2. 从控制面板卸载MySQL for Visual Studio

    3. 根据下表重新安装

    4. 将程序集文件从 c:\program files(x86)\mysql\mysql connector net 6.9.8\assembles\v4.5 复制到 c:\program files(x86)\microsoft Visual Studio 12.0\common7\ide

    5. 注销并重新打开解决方案

    6. 享受

    最后:

    1. 卸载连接器

    2. 从控制面板卸载MySQL for Visual Studio

      click here

    3. 根据下表重新安装

      click here

    4. 从复制程序集文件 C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.5 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE

    5. 注销并重新打开解决方案

    6. 享受

        5
  •  7
  •   Community Mohan Dere    9 年前

    这似乎是一个常见的问题。我必须卸载最新的connector/net驱动程序(6.7.4)并安装一个旧版本(6.6.5),以便它工作。其他人报告6.6.6为他们工作。

    更多信息请参阅其他主题: MySQL Data Source not appearing in Visual Studio

        6
  •  7
  •   Ognyan Dimitrov    11 年前
    1. 从下载mysql connector.net(此日期为6.9.4) here 安装它 习俗 !
    2. 删除ASP.NET Web Providers选项,否则安装程序将写入machine.config!
    3. 从下载MySQL for Visual Studio here 安装它 习俗 . 一定要检查集成选项。您需要执行此步骤,因为在连接器.NET 6.7之后,安装程序将不再将连接器与Visual Studio集成。此安装程序可能需要比预期更长的时间。就是这样。

    您可以从备用下载安装它 here 它应该与vs正确集成,但它没有,我得到了一个奇怪的错误,重新安装后,它是正常的。

        7
  •  2
  •   Onjon Shahadat    10 年前

    View Image 在64位机器上,我的vs 2013也有同样的问题。所以我试着下载 MySql extension for VS 把它安装在我的机器上。重新启动vs.

        8
  •  1
  •   Jordan    9 年前

    为了得到 MySQL数据库 项目中 选择数据源 窗口,应该安装 用于Visual Studio的MySQL 此处提供的程序包(今天的最新版本是 1.2.6 ):

    https://dev.mysql.com/downloads/windows/visualstudio/

        9
  •  1
  •   Jeff D    9 年前

    右键单击解决方案资源管理器中的项目,然后单击管理Nuget包。

    搜索mysql.data包,找到后单击Install。

    下面是使用mysql包连接到mysql数据库的示例控制器。我们主要使用mysqlconnection连接对象。

     public class HomeController : Controller
    {
        public ActionResult Index()
        {
            List<employeemodel> employees = new List<employeemodel>();
            string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
            using (MySqlConnection con = new MySqlConnection(constr))
            {
                string query = "SELECT EmployeeId, Name, Country FROM Employees";
                using (MySqlCommand cmd = new MySqlCommand(query))
                {
                    cmd.Connection = con;
                   con.Open();
                    using (MySqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            employees.Add(new EmployeeModel
                            {
                                EmployeeId = Convert.ToInt32(sdr["EmployeeId"]),
                                Name = sdr["Name"].ToString(),
                                Country = sdr["Country"].ToString()
                            });
                        }
                    }
                    con.Close();
                }
            }
    
            return View(employees);
        }
    }
    
        10
  •  0
  •   Ali Tarhini    15 年前

    不幸的是,Visual Studio中的内置工具不支持此功能。但是,您可以使用mysql connector创建自己的数据提供程序,但仍然必须从代码中集成它。