RoR
RoR

Reputation: 16472

Trying to connect to mysql db with C#

When I debug through the code just hangs on connection.Open();

I am using the connector - using MySql.Data.MySqlClient;

Thanks in advance.

        string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;

        MySqlConnection connection = new MySqlConnection(strProvider);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;
        command.CommandText = "select * from products";
        connection.Open();
        Reader = command.ExecuteReader();
        while (Reader.Read())
        {

            string thisrow = "";
            for (int i = 0; i < Reader.FieldCount; i++)
                thisrow += Reader.GetValue(i).ToString() + ",";
            listBox1.Items.Add(thisrow);
        }
        connection.Close();

Upvotes: 1

Views: 297

Answers (1)

Rumplin
Rumplin

Reputation: 2768

This will help http://www.connectionstrings.com/mysql

You need to change your connection string for MySQL

Upvotes: 3

Related Questions