Connect a Windows 8 application to MySQL

I am making my first application for Windows 8 using C #. I have a MySQL database that I would like to connect to. I did this before with window shapes and everything went smoothly. However, with window 8, the application will not connect.

This is my connection string:

string myConnectionString = "Server=mysql9.000webhost.com; Database=a2236339_snooker; Uid=a2236339_joe; password=TeamPr0ject;"; 

The code looks like this:

 MySqlConnection connection = new MySqlConnection(myConnectionString); connection.Open(); 

and then open my connection.

The error I get is

An exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.RT.DLL, but was not processed in the user code

Can someone explain why this is so and what I am doing wrong?

+1
c # mysql
source share
2 answers

I can’t see the rest of your code, but if I did the connection, I would do it right:

 using (MySqlConnection connection = new MySqlConnection("server=YOUR_SERVER;database=YOUR_DATABASE;uid=YOUR_USERNAME;password=YOUR_PASSWORD;")) { connection.Open(); MySqlCommand userinfoCommand = new MySqlCommand("SELECT name, FROM table",connection); using (MySqlDataReader reader = userinfoCommand.ExecuteReader()) { while (reader.Read()) { String name= reader.GetString("name"); } connection.Close(); } } 
0
source share
 using (MySqlConnection connection = new MySqlConnection("server=YOUR_SERVER;database=YOUR_DATABASE;uid=YOUR_USERNAME;password=YOUR_PASSWORD;")) { connection.Open(); MySqlCommand userinfoCommand = new MySqlCommand("SELECT name, FROM table",connection); using (MySqlDataReader reader = userinfoCommand.ExecuteReader()) { while (reader.Read()) { String name= reader.GetString("name"); } connection.Close(); } } 
0
source share

All Articles