tags:

views:

35

answers:

1

So, I'm sort of a beginner on C# and I'm working on this project that needs a connection to a MySQL database.

I got MySQL's own library for this and, just to test the connection, I wrote this code:

public object connectionTest()
{
    MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
    builder.Server = "localhost";
    builder.Database = "base1";
    builder.UserID = "root";
    builder.Password = "";

    MySqlConnection conn = new MySqlConnection(builder.ConnectionString);
    conn.Open();
    return conn;
}

But neither the localhost database, nor the online database will respond. The password being blank or not.

My local database is installed through XAMPP - can this be a problem? Even if it was, it still should connect to the online database. Is there any restriction for C# to work with MySQL?

Using C#'s SqlConnection instead of MySqlConnection, the conn object is always initialized with its State attribute set to "Closed". I'm not sure if this happens because the database server isn't responding as with the MySqlConnection class or because of something else.

Any thoughts?

A: 

Can you access the MySQL database via MySQL Administrator or MySQL Query Browser? Perhaps it is not running as a service and thus is not available to the MySQL connection.

John M