Connect to MySQL via C# .NET (Visual studion 2008)

Which client library can we use to connect to a MySQL 5.0 database from MS .NET Visual Studio 2008 code?

I use
using System.Data.OracleClient;;
using System.Data.SqlClient;

for Oracle and SQL server databases respectively.

Who is Participating?
Rose BabuSenior Team ManagerCommented:

Alternatively you can test this too.

You need to download and install the mysql connector/net. you can download it from

then in your project, add reference to MySql.Data

then add "using MySql.Data.MySqlClient;"

in your code part add the following code,

private void button1_Click(object sender, System.EventArgs e)
	string MyConString = "SERVER=localhost;" +
		"DATABASE=Northwind;" +
		"UID=testuser;" +
	MySqlConnection connection = new MySqlConnection(MyConString);
	MySqlCommand command = connection.CreateCommand();
	MySqlDataReader Reader;
	command.CommandText = "select * from Customers";
	Reader = command.ExecuteReader();

	string rowData = "";
	while (Reader.Read())

		for (int i= 0;i<Reader.FieldCount;i++)
			rowData += Reader.GetValue(i).ToString() + ", ";

		rowData += "<br />"

	literal1.text = rowData;


Open in new window

Happy Programming.
You can either use ODBC or MySql Client for .NET.


1. Download MySql Client dll.
2. Add the dll to your project.

3. Add connection string to web.config

    <add name="Connstring" connectionString="server=localhost; userid=uid;password=pwd;pooling=yes;Database=DB" providerName="MySql.Data.MySqlClient"/>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>


thatt's it you can follow same sqlclient connection.

toookiAuthor Commented:
Thank you.
I am going to check the details you sent to me.
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Mohamed AbowardaSoftware EngineerCommented:
You can try OleDbConnection class:

This way will allow you to connect to any of the most common databases by just changing the connection string.

The following website can help you to determine the appropriate connection string:
toookiAuthor Commented:
Thank you. I am going to check this.
toookiAuthor Commented:
Thanks srosebabu. I am going to try this soon.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.