none
unable to connect to any of the specified mysql RRS feed

  • Question

  • Hi,

    I am trying to connect from C# WinForm application to MySQL but getting the above error.

    MySQL is on CentOS and I am connected through NaviCat without any problem with enabling SSH Tuning option in NaviCat.

    here is my code in C#:

    sql_connection = new MySqlConnection(xmlClass.get_connectionstring("BizCards\\BizCards"));
    sql_connection.Open();
    
    sql_command = new MySqlCommand("sp_populate_countries", sql_connection);
    sql_command.CommandType = CommandType.StoredProcedure;
    
    // Create data adapter object 
    sql_adapter = new MySqlDataAdapter();
    sql_adapter.SelectCommand = sql_command;
    
    // Create a dataset object and fill with data using data adapter's Fill method 
    data_set = new DataSet();
    sql_adapter.Fill(data_set, "countries");
    DataViewManager dataview_manager = new DataViewManager(data_set);
    DataView main_dataview = dataview_manager.CreateDataView(data_set.Tables["countries"]);
    
    cboCountry.Properties.ValueMember = "country_code_alpha2";
    cboCountry.Properties.DisplayMember = "country_name";
    cboCountry.Properties.DataSource = main_dataview;
    
    cboCountry.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("country_name", 50, "country_name"));
    
    cboCountry.Properties.ShowHeader = false;
    
    cboCountry.Properties.PopupSizeable = false;
    cboCountry.Properties.ShowFooter = false;
    cboCountry.Properties.PopupWidth = 50;
    




    Sunday, June 22, 2014 8:15 AM

Answers

  • I assume you are getting the error on the Open() method. There can only be 4 reasons.

    1) No connection path - Server cannot be reached or Port number is wrong.  The timeout may be too small.

    2) Credentials are wrong

    3) The connection is already open.  You can only have one connection with the same Source IP address, Destination IP Address, and port number

    4) The Port number is being blocked by a firewall or virus checker

    You may want to check Control Panel : Administrative Tools : Event View.  Check at both client and server. Also add a exception handler to get more info.

     

    jdweng

    Sunday, June 22, 2014 12:01 PM

All replies

  • Is the database on the same PC as the application?  You application need to have access to the database folder where the database file is located.  Start by opening a windows explorer and make sure you can find the path for the database file in the windows explorer.  You may need to make the folder shared so you have access to the file path where the database is located.

    jdweng

    Sunday, June 22, 2014 9:13 AM
  • it's on a remote server. I have access to the server and I am able to connect using NaviCat as mentioned but ot through my C# application
    Sunday, June 22, 2014 9:26 AM
  • You probably have a credential issue.  What is your connection string? Make sure it looks like one of the connection string on the webpage  below

    http://www.connectionstrings.com/mysql/


    jdweng

    Sunday, June 22, 2014 9:45 AM
  • how come it's credential issue and I am able to connect using NaviCat?!!!

    this is my connection string:

    server=xx;port=xx;database=xx;uid=xx;pwd=xx;connection timeout=xx


    Sunday, June 22, 2014 9:48 AM
  • I though you were connecting using a path instead of a port.  Can you ping the server in a cmd.exe window?

    Ping xx

    You PC may have more than one Ethernet card and IP address may not be reachable from the network card attached to windows but reachable through the 2nd Ethernet card that NaviCat is using.


    jdweng

    Sunday, June 22, 2014 10:14 AM
  • yes I can ping.
    Sunday, June 22, 2014 10:49 AM
  • I assume you are getting the error on the Open() method. There can only be 4 reasons.

    1) No connection path - Server cannot be reached or Port number is wrong.  The timeout may be too small.

    2) Credentials are wrong

    3) The connection is already open.  You can only have one connection with the same Source IP address, Destination IP Address, and port number

    4) The Port number is being blocked by a firewall or virus checker

    You may want to check Control Panel : Administrative Tools : Event View.  Check at both client and server. Also add a exception handler to get more info.

     

    jdweng

    Sunday, June 22, 2014 12:01 PM