How to connect MySQL with C#?

r10x

New member
Joined
Apr 13, 2010
Messages
1
Hello!
I have created a database and uploaded my website to my site and it works fine, but when I try to stablish a MySQL connection from an interface I programmed in C#, it fails and it shows the message: "unable to connect to any of the specified hosts"...what am I doing wrong?? I'm using the following command to connect to MySQL...It does work with localhost in my computer....but it doest´t work with my webpage.

MySqlConnection conexion_global_MySQL = new MySqlConnection("Data Source=http://65.99.205.174:3306; Database=mexatronic_controldeaccesos;User ID=X;Password=***");

Could you please help me to figure out how to connect my C# application with my webpage?

Thanks
 
A quick Google shows this:

Code:
using System;
using MySql.Data.MySqlClient;

namespace ConsoleApplication1
{
class ConnectToMySQL
{
    [STAThread]
    static void Main(string[] args)
    {
        //create a MySQL connection with a query string
        MySqlConnection connection = new MySqlConnection("server=localhost;database=cs;uid=root;password=abcdaaa");

        //open the connection
        connection.Open();

        //close the connection
        connection.Close();
    }
}
}

so in your code it's a little different - perhaps try this:

Code:
MySqlConnection connection = new MySqlConnection("server=65.99.205.174;database=mexatronic_controldeaccesos;uid=X;password=***"

notice there's no "http://" and there's no ":3306" in the server attribute. User ID is "uid".
 
You also have to tell mysql to allow other host connections. And make sure port 3306 is open.
 
Back
Top