Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-05-03
Medium Priority
Last Modified: 2013-12-16
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.

Question by:toooki
LVL 53

Assisted Solution

Dhaest earned 948 total points
ID: 35513724
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.

Source: http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/878d58e5-0f54-4cde-b8b5-e66ee92d53ce/

Author Comment

ID: 35514507
Thank you.
I am going to check the details you sent to me.
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35688936
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:
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  


Author Comment

ID: 35717514
Thank you. I am going to check this.
LVL 16

Accepted Solution

Rose Babu earned 952 total points
ID: 35785206

Alternatively you can test this too.

You need to download and install the mysql connector/net. you can download it from http://dev.mysql.com/downloads/connector/net/1.0.html

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.

Author Comment

ID: 35819607
Thanks srosebabu. I am going to try this soon.

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question