23 August, 2011
0 Comments
1 category
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};",
"192.168.1.1", "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)); } } }
Category: Uncategorized
I’ve been stumbled with MySql ODBC connection for 2 hours and then read this post that talks about which connector to use: http://bobobobo.wordpress.com/category/mysql/. I decided to use ADO.NET and came across your post. Your post was helpful and quickly helped to solve my problem. Thank you!