I want to connect to mysql server from C#. I found some code on the net but somewhere there is something wrong because i get
A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
error.
private void Initialise() { server = "dns to server"; database = "db_name"; uid = "root"; password = "password"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; OR connectionString = "Server=xxx.no-ip.org;Database=rdb;"+ "Uid=root;Pwd=wHt2%Zt;"; connection = new MySqlConnection(connectionString); if (this.OpenConnection() == true) Console.Out.Write("SUCCESS"); else Console.Out.Write("ERROR"); } private bool OpenConnection() { try { connection.Open(); return true; } catch (MySqlException ex){ switch (ex.Number) { case 0: MessageBox.Show("Cannot connect to server. Contact administrator"); break; case 1045: MessageBox.Show("Invalid username/password, please try again"); break; } return false; } } I don't get any message on the console. I added Mysql.Data as a reference to my project and i used using MySql.Data.MySqlClient;
I also tried connectig through gui but with no luck. Ideas ?
Edit 1 : with either connection string my program is still not working.
Edit 2 : OpenConnection method added.
Edit 3 : This is the error i get !