How to connect to a MySQL Data Source in Visual Studio

前端 未结 11 2068
忘了有多久
忘了有多久 2020-11-28 09:15

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

相关标签:
11条回答
  • 2020-11-28 09:37

    "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

    0 讨论(0)
  • 2020-11-28 09:39

    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

    0 讨论(0)
  • 2020-11-28 09:39

    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.

    0 讨论(0)
  • 2020-11-28 09:40

    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);
        }
    }
    
    0 讨论(0)
  • 2020-11-28 09:48

    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)

    0 讨论(0)
  • 2020-11-28 09:52

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

    alt text

    0 讨论(0)
提交回复
热议问题