0

I'm trying to connect MySQL in C# develope in Expression Blend 4 but i get following error ?

try
        {
            string serverConnection = "SERVER=xxx.xxx.xxx.xxx; UID=xxx; PASSWORD=xxx; DATABASE=xxx;";
            MySqlConnection conn = new MySqlConnection(serverConnection);
            conn.Open();
            MessageBox.Show("Successfully connected");
            conn.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error:"+ex.Message);
        }

Here is the error:

Unable to connect to any of the specified MySQL hosts
6
  • Any inner exception? can you connect to mySql from another MySQL Managers? Commented Apr 8, 2015 at 16:42
  • Yes it works fine in another. There is one exception here conn.Open(); Commented Apr 9, 2015 at 2:21
  • Is MySql using the default port 3306? Commented Apr 9, 2015 at 6:38
  • Yes it is, local server worked but remote server says these error Commented Apr 9, 2015 at 7:07
  • Did you config your MySQl to accept remote connections to your IP? you need to grant permissions first. cyberciti.biz/tips/… Commented Apr 9, 2015 at 7:14

2 Answers 2

1

The format for connection strings is as follows,

Server=myServerAddress; Port=1234; Database=myDataBase; Uid=myUsername; Pwd=myPassword;

The most likely issue is that you are trying to remotely connect to your MySQL server in which case make sure it allows for remote connections, and then you must check and make sure the user you are trying to login as is allowed to connect from either your public IP or any public IP.

NOTE: I know this response is 2 and 1/3 years late, but I wanted this to be here for anyone else with a similar issue.

Sign up to request clarification or add additional context in comments.

Comments

1

I think its more of like the placement of the parameters.

The standard format specified is this:

Server=myServerAddress; Port=1234; Database=myDataBase; Uid=myUsername; Pwd=myPassword;

You need to change it like this:

string serverConnection = "SERVER=xxx.xxx.xxx.xxx; DATABASE=xxx; UID=xxx; PASSWORD=xxx;";

Try to change and see if that works :)

1 Comment

Thanks for reply, but it doesn't work same as before :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.