Download the MySQL drivers at: http://dev.mysql.com/downloads/connector/net/

Install the drivers on you’re development machine.


At references to:

– System.Data

– MySql.Data [C:\Program Files (x86)\MySQL\MySQL Connector Net 6.4.3\Assemblies\v4.0\MySql.Data.dll]


The following code will output all database names to the console window:

using System.Data;
using MySql.Data.MySqlClient;
string connectionString = String.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};",
"", "3306", "MyDatabaseName1", "MyUserName1", "MyPassword1"); using (MySqlConnection connection = new MySqlConnection(connectionString)) { using (MySqlCommand cmd = new MySqlCommand("SHOW DATABASES", connection)) { connection.Open(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader.GetString(0)); } } }

One Reply to “How to connect to MySQL by using ADO .NET and C# 4.0”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

2020-06-17 Learned Today


  FaviconsWebpackPlugin - Generating all favicon images during development build…