I'm new to MySQL Workbench and I'm trying to make a Timekeeping system. I'm wondering how to connect MySQL with Visual Studio C#?
Connect C# to MySQLAll the communication between a C# application and the MySQL server is routed through a MySqlConnection Object. So, before your application can communicate with the server, it must instantiate, configure, and open a MySqlConnection object.
Many MySQL for Visual Studio features also require that MySQL Connector/NET be installed on the same host where you perform Visual Studio development. Connector/NET is a separate product. The options for installing MySQL for Visual Studio are: Using MySQL Installer (preferred): Download and execute the MySQL Installer.
you'll need a "connector/driver" to connect from .net to mysql, you can find the official .net connector from mysql here:
http://dev.mysql.com/downloads/connector/net/
the connector will install the MySql.Data library that you has classes to communicate to MySql (MySqlConnection, MySqlCommand, MySqlDataAdapter, etc)
If you are working with MySQL for the first time in your PC, do these things.
Now install SqlYog Community Edition. ( Link here ). You can manipulate your MySQL Databases using this.
Now in AppSettings of web.config, set two entries like this.
<configuration>
<appSettings>
<add key="ODBCDriver" value="Driver={MySQL ODBC 5.1 Driver};Server=localhost;"/>
<add key="DataBaseDetails" value="Database=mydatabase;uid=root;pwd=;Option=3;"/>
</appSettings>
</configuration>
And call it like in your MySQL class like this.
public string MyConnectionString
{
get
{
//return {MySQL ODBC 5.1 Driver};Server=localhost;Database=mydatabase;uid=root;pwd=;Option=3;
return ConfigurationManager.AppSettings["ODBCDriver"]
+ ConfigurationManager.AppSettings["DataBaseDetails"];
}
}
Now you can initialize your connection like this.
OdbcConnection connection = new OdbcConnection(MyConnectionString);
Namespace imported
using System.Data.Odbc;
Hope you get the idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With