0

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.

Sagotharan
  • 2,586
  • 16
  • 73
  • 117
  • 1
    Have you tried running Visual Studio as administrator? – ChrisBD Jan 23 '12 at 17:42
  • No Sir, What is the Need for that?. Now i try it sir. But Same error repeat. – Sagotharan Jan 23 '12 at 17:44
  • 1
    Aren't you missing a password field from the connection string? – ChrisBD Jan 23 '12 at 17:56
  • I have tried "server=192.168.1.100;User Id=mcubic;password=mcs@2011$;Persist Security Info=True;Initial Catalog=mcubic;pooling=False"; Also Sir,. But no use. Any Special Connection String for Smart Devices – Sagotharan Jan 23 '12 at 18:11
  • 1
    Hi @Sagotharan, do you know what port your database server is running on? Is it the default 3306? You can specify this in the connection string by appending ;port=xxxx on the end of your connection string. Also make sure the MySql server is running! – dash Jan 23 '12 at 19:42
  • In Windows Application This Code is worked Correctly. But in Smart Devices it not work. Anyway i tried "server=192.168.1.100;User Id=mcubic;password=mcs@2011$;Persist Security Info=True;Initial Catalog=mcubic;port=3306"; Connection String Also. – Sagotharan Jan 23 '12 at 20:01
  • 1
    If you restart MySql does it help? Just make sure it's not a state issue. If you downgrade to connector 6.3.8 does that make a difference? I checked and that is the version we are using. – dash Jan 23 '12 at 21:12
  • 1
    Also, use the simplest connection string possible: Server=192.168.1.100;Port=3309;Database=Test;Uid=mcubic;Pwd=mcs@2011$; (don't include the persist security info section) – dash Jan 23 '12 at 21:20
  • I am using MySQL Connector Net 6.4.4. I can't find why this repeating. I will try and tell mr.dash. Thank you very much to support me. – Sagotharan Jan 24 '12 at 05:27
  • 1
    Is this a compiled application or is it running in VS emulator? – ChrisBD Jan 24 '12 at 08:16
  • No I have Close the emulator when the programs finished. The first execution itself this problem repeats. – Sagotharan Jan 24 '12 at 08:22

2 Answers2

2

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();
0

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.

ChrisBD
  • 9,104
  • 3
  • 22
  • 35