locked
ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10061) RRS feed

  • Question

  • User222693409 posted

    Greetings all!

    I have this weird error "ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10061)" on my website that is supposed to connect to a MySQL database on a different server (NOT localhost).

    Here's the scenario:

    I develop my ASP.Net 2.0 website on my PC using this connection string for my ObjectDataSource:

    <add name="ConnectionString" connectionString="Driver={MySQL ODBC 3.51 Driver};server:localhost; database=MYDBASE;uid=MYUID;pwd=MYPWD" providerName="System.Data.Odbc" />

    After testing and finding all pages working fine, I changed my connection string by replacing the server name to that specified by my Internet Hosting Company (along with the relevant dbase, uid, and pwd), buit my website and published it to a different virtual address on my local server (using Web Deployment Manager), and then copied the files onto my internet webspace.

    The weird thing is that the error keeps referring to the LOCALHOST server (this is the one I use in my Local PC).

    Could somebody please help resolve this problem? I've been trying to fix this error for a couple of days now and seem to be stuck with it. :(

    Thanks.

    Wednesday, April 12, 2006 9:32 AM

All replies

  • User143635943 posted
    Hello,

    Recheck your connection string. Also do one more thing to check connection. If you've MySQL administrator or Query browser tool, enter the name of server and database in it and test the connection.
    Also try using IP instead of server name.

    Regards

    Kuldeep Deokule
    Monday, May 1, 2006 12:53 PM
  • User-1226486387 posted
    We kinda got the exact same error.

    Site was running fine. Then our customer calls in to say he gets an error. We check it, the asp.net app won't connect to MySQL. We restart MySQL, and it works fine. 10 min later, same thing happen !

    I restart the MySQL Service and check to see if I can connect to using the mysql consol (in dos) and it just won't let me in, saying it can't connect to mysql !

    we restart the server, and it works fine.

    Any idea ? ASP.NET 1.1 and MySQL Connector 3.51 .

    Thanks
    Monday, May 1, 2006 4:11 PM
  • User222693409 posted

    I discovered that the cause of the problem was my using ODBC driver instead of MySQL Connector; apparently my ISP does not support ODBC.  Also I was using

    I rewrote the connection string in my web.config file and now my application works.

    Regards,

    Tuesday, May 2, 2006 12:40 AM
  • User-1226486387 posted

    could you show me your connection string (hiding your credential). Thanks

    Tuesday, May 2, 2006 12:55 PM
  • User222693409 posted

    Sure.  In the web.config file, i have the following entry:

    <configuration>
      <connectionStrings>
        <add name="myConStringName" connectionString="server=MYSERVER; database=MYDBASE; user id=MYUSERID; password=MYPASSWORD;  pooling=false"/>
       </connectionStrings>
    </configuration>

    Please note the above connectionstring is for ASP.Net 2.0.  For 1.1, the correct signature is as follows:

    <add key="myConStringName" value="driver={MySQL ODBC 3.51 Driver}; server:MYSERVER; database=MYDBASE; user=MYUSERID; password=MYPASSWORD;"/>

    Regards,

    Wednesday, May 3, 2006 12:29 AM
  • User363754837 posted

    Hello i know it's been a while since you posted the above post but i am having the same problem you had in the past using mysql connection string i cannot connect to my database using the same conenction string you provided i know you said that you used mysql connector but how did you implemented it in you web config file or your page because i did not see you referring to it inside your code.

    Best Regards

    Friday, May 29, 2009 2:21 PM
  • User318696944 posted

    I figured out the answer and it was a simple one, masterpage1. While I thought that I added my IP address/Class C to the Remote MySQL Access Host list (which is located in cPanel, if that's what your host is using), I forgot that I was connecting from a different location. Once I added my IP address, everything worked perfectly.

    Here is the connection code I used to get my desktop application to work. Specifically, I am using Microsoft Visual Basic 2010 Express with MySQL ODBC Driver 5.1 in a Microsoft Windows XP 32-bit environment. The server I connected to is a Linux shared server running cPanel 11.30.3 (build 5) and MySQL version 5.1.59

    The MySQL ODBC Driver I used is available here.
    Specifically, for 32-bit, mysql-connector-odbc-5.1.9-win32.msi is the direct download

    Below is the code I used to connect. I hope it helps others out there.

    Sub OpenMySQLConnection()
    Dim mConnection As Odbc.OdbcConnection

    ' First, build a connection if one doesn't already exist
    If mConnection Is Nothing Then mConnection = New Odbc.OdbcConnection

    ' Is the connection is already open? If so, close it.
    If mConnection.State = ConnectionState.Open Then mConnection.Close()

    ' Initialize a few local variables to store the MySQL username, password, location, driver name and database name.
    Dim username As String = "mySQLusername"
    Dim password As String = "mySQLpassword"
    Dim server As String = "somewhere.doc"
    Dim driver As String = "{MySQL ODBC 5.1 Driver}"
    Dim database As String = "mySQLdatabaseName"

    ' Build the connection string object
    myConnectionString = "Driver=" & driver & "; Server=" & server & "; User=" & username & "; Password=" & password & ";Database=" & database & ";"

    ' Now attempt to open the connection to the database
    mConnection.ConnectionString = myConnectionString
    Try
    mConnection.Open()
    Catch ex As Exception
    'Unable to connect. To read the error, add this to a message box somewhere: ex.ToString
    'For example: MsgBox("Unable to connect due to the following error: " & ex.ToString)
    'Write code below to execute more steps since you're unable to connect.
    End Try

    ' See if the connection state opened correctly (successfully)
    If mConnection.State <> ConnectionState.Open Then
    'Execute code if an error occurred while attempting to open
    ElseIf mConnection.State = ConnectionState.Open Then
    'All is well! Insert additional code to manipulate database here
    End If
    End Sub
    Sunday, November 13, 2011 11:43 AM