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
"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
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
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.
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);
}
}
Installing the following packages:
adds MySQL Database to the data sources list (Visual Studio 2017)
install the MySQL .NET Connector found here http://dev.mysql.com/downloads/connector/net/