"Unable to connect to any of the specified MySQL hosts." in Smart Device Projects VS2008

6k views Asked by At

I am new to Smart Device Projects. I installed MySQL Connector Net 6.4.4. And i add MySql.Data.CF for mysql connection in vs 2008.

But i can't get the output. "Unable to connect to any of the specified MySQL hosts." exception through on the connection.open().

server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic

its a working Connection string. So database server user id, password are correct. No issue in that. But i can't understand why it through error on Smart Device Projects only.

The code given below.

try
 {
    string connectionString = "server=192.168.1.100;User Id=mcubic;Persist Security Info=True;database=mcubic";
    string query = "select b.Outlet_Master_Name from mcs_user_outlet a,outlet_master b where a.Mcs_User_Outlet_User_Id=3 and a.Mcs_User_Outlet_Outlet_Id = b.Outlet_Master_Id";
    MySqlConnection connection = new MySqlConnection(connectionString);
    MySqlCommand command = new MySqlCommand(query, connection);
    connection.Open();
    MySqlDataReader Reader = command.ExecuteReader();
    while (Reader.Read())
    {
        comboBox1.Items.Add(Reader[0].ToString());
    }
    connection.Close();
 }
catch(Exception ex)
{
     MessageBox.Show(""+ex.Message);
}

Help me to find out the error.

I have tried below Connection Strings.

server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic

server=192.168.1.100;User Id=mcubic;Persist Security Info=False;database=mcubic

server=192.168.1.100;User Id=mcubic;Persist Security Info=False;Initial Catalog=mcubic;

server=192.168.1.100;UID=mcubic;Persist Security Info=True;database=mcubic;pooling = false;

But No Use.

2

There are 2 answers

0
ChrisBD On

I think that your problem may be due to the way in which Smart Devices connect to external networks. I take it that you're trying to run this from Visual Studio using an emulator.

I gather that you need to connect to the external network on which your MySql server resides before attempting to connect to the server itself.

There's an article here that covers your problem but with SQL Server. I'm sure that it would cover the same problem that your experiencing.

1
Martyn Snake On

I solve my problem. Hope this helps you too. Code below is working perfectly for me.

    DataSet ds = new DataSet();
    MySqlConnection conn = new MySqlConnection("server=server-ip;database=db-name;Character Set=utf8;Uid=user-name;password=****;");
    MySqlCommand cmd = new MySqlCommand("select * from table-name", conn);
    MySqlDataAdapter da = new MySqlDataAdapter();
    conn.Open();
    da.SelectCommand = cmd;
    da.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
    conn.Dispose();
    cmd.Dispose();