none
MySQL error... cannot connect to DB

    Question

  • Hi all,

    I have installed VB and below is the code I have for a SUB procedure. 

    My global headings include

    Imports System.Data
    Imports System.Windows.Forms
    Imports MySql.Data.MySqlClient

    Public Class NAME HERE
        Inherits System.Windows.Forms.Form

        Dim conn As MySqlConnection
        Dim data As DataTable
        Dim da As MySqlDataAdapter
        Dim cb As MySqlCommandBuilder


     If Not conn Is Nothing Then conn.Close() 
            Dim connStr As String 
            connStr = "Server=server;" & _ 
      "Database=DB;" & _ 
      "Uid=root;" & _ 
      "Pwd=password;" & _ 
      "Connect Timeout=30;" 
            Try 
                conn = New MySqlConnection(connStr) 
                conn.Open() 
     
                '  GetDatabases() 
            Catch ex As MySqlException 
                MessageBox.Show("Error connecting to the server: " + ex.Message) 
            End Try 

    However, when I try to run the program, I receive the message




    Error connecting to the server: Unable to connect to any of the specified MySQL hosts.
    I have tried it with a local server and a remote server. It seems to be the code...

    Can any one provide the "basics" needed to connect to a MySQL server or see what code is wrong above?

    Thank you!



    Tuesday, December 09, 2008 10:22 PM

All replies

  • :) I have never found way how to connect to remote mysql server. If it is mySql server with some online provider, it is caused with "connectionsAllowedToSingleServer" setting, which limits your database to be accessed only from related webhosting. Only option which worked (and works) for me ever is localhost mySql... But I am sure there is option to modify sql server config, if you are its owner or qualified person to do this.

    best wishes, matt
    Posting you abusive right now, and all of your posts!
    • Proposed as answer by konikula Thursday, December 11, 2008 1:51 AM
    Tuesday, December 09, 2008 10:44 PM
  • Have You Made Sure Nothing Is Blocking The Connection To Your MySQL Server?
    Wednesday, December 10, 2008 7:44 AM
  • That seems about right. No connections are being blocked as far as I know, so it must be MySQL itself...

    Thanks =)
    Wednesday, December 10, 2008 10:15 AM
  • But if you will not find solution on MySql side, please let us know. I am still not very satisfied with my experiences on MySql & .NET - and who knows ;)?

    best wishes, matt
    Posting you abusive right now, and all of your posts!
    • Proposed as answer by konikula Thursday, December 11, 2008 1:51 AM
    • Unproposed as answer by Martin Xie - MSFT Monday, December 15, 2008 7:02 AM
    Thursday, December 11, 2008 1:50 AM
  • Thank you All for your friendly help.

    Hi xtrafile,

    Welcome to MSDN forums!

    Here are some references:

    1. We can connect and access MySQL database via three approaches:

    • The ODBC.NET Solution - MyODBC Driver
    • Using MySQL Native .NET Providers (This is your scenario.)
    • Using the OLEDB.NET Solution - MyOLDDB Provider

    Please check this document for detailed instruction and code sample:

    Exploring MySQL in the Microsoft .NET Environment.

     

    2. Here are various connection strings to MySQL in .NET.

    http://www.connectionstrings.com/?carrier=mysql



    Move it to ADO.NET Data Providers forum for better responses.


    Best regards,
    Martin Xie

    Monday, December 15, 2008 7:21 AM