How to connect to a MySQL Data Source in Visual Studio

做~自己de王妃 提交于 2019-11-26 09:09:06

问题


I use the MySQL Connector/Net to connect to my database by referencing the assembly (MySql.Data.dll) and passing in a connection string to MySqlConnection. I like that because I don\'t have to install anything.

Is there some way to \"Choose Data Source\" in Visual Studio 2010 without installing something?

How can I get a MySQL option (localhost) to show up on one of these lists? Or do I have to install something?

(I don\'t want to use ODBC btw)

\"Add Connection\" from Server Explorer: \"alt

Entity Data Model Wizard: \"alt


回答1:


Visual Studio requires that DDEX Providers (Data Designer Extensibility) be registered by adding certain entries in the Windows Registry during installation (HKLM\SOFTWARE\Microsoft\VisualStudio\{version}\DataProviders) . See DDEX Provider Registration in MSDN for more details.




回答2:


install the MySQL .NET Connector found here http://dev.mysql.com/downloads/connector/net/




回答3:


"Starting with version 6.7, Connector/Net will no longer include the MySQL for Visual Studio integration. That functionality is now available in a separate product called MySQL for Visual Studio available using the MySQL Installer for Windows."

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




回答4:


After a lot of searching and trying many solutions, I got it finally:

  1. uninstall connector

  2. uninstall MySQL for Visual Studio from control panel

  3. reinstall them according to the table below

  4. copy the assembly files from C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.5 to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE

  5. log off and reopen your solution

  6. enjoy




回答5:


This seems to be a common problem. I had to uninstall the latest Connector/NET driver (6.7.4) and install an older version (6.6.5) for it to work. Others report 6.6.6 working for them.

See other topic with more info: MySQL Data Source not appearing in Visual Studio




回答6:


  1. Download MySQL Connector .NET (6.9.4 on this date) from here and install it CUSTOM!
  2. Remove the ASP.NET WEB providers option or the installer will write in machine.config!
  3. Download MySQL for Visual Studio from here and install it CUSTOM. Be sure to check the integration options. You need this step because after Connector .NET 6.7 the installer will no longer integrate the connector with Visual Studio. This installer can take longer then expected. This is it.

You can install it from alternate download here which should have integrated with VS correctly but it did not and I got a strange error and after the reinstall it is ok.




回答7:


View ImageI have got the same problem for my vs 2013 on 64-bit machine. So i tried to download MySql extension for VS and install it on my machine. and restart the vs.




回答8:


Installing the following packages:

  • Connector/NET 8.0.16: https://dev.mysql.com/downloads/connector/net/
  • MySQL for Visual Studio 1.2.8: https://dev.mysql.com/downloads/windows/visualstudio/

adds MySQL Database to the data sources list (Visual Studio 2017)




回答9:


In order to get the MySQL Database item in the Choose Data Source window, one should install the MySQL for Visual Studio package available here (the last version today is 1.2.6):

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




回答10:


Right Click the Project in Solution Explorer and click Manage NuGet Packages

Search for MySql.Data package, when you find it click on Install

Here is the sample controller which connects to MySql database using the mysql package. We mainly make use of MySqlConnection connection object.

 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);
    }
}



回答11:


unfortunately this is not supported in the builtin tools in visual studio. however, you can create your own data provider using mysql connector but still have to integrate it from code



来源:https://stackoverflow.com/questions/4235291/how-to-connect-to-a-mysql-data-source-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!