Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [MySQL][ODBC 8.0(w) Driver] Can't connect to MySQL server on 'localhost' (10061) QODBC3: Unable to connect"

[MySQL][ODBC 8.0(w) Driver] Can't connect to MySQL server on 'localhost' (10061) QODBC3: Unable to connect"

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by U7Development
    #1

    Hi!..

    I have installed a Windows computer having MariaDB installed, its ip is 192.168.1.200, now I'm trying to connect through another computer on the same LAN, the ODBC connector on Data Sources (Windows) test connection successfuly so driver is working fine...

    Tried this example to test the remote connection:

    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
        db.setDatabaseName("Driver={MySQL ODBC 8.0 Unicode Driver};Database=db0");
        db.setPort(3306);                                     //Update: this has no effect
        db.setHostName("192.168.1.200");   //Update: this has no effect
        db.setUserName("root");         
        db.setPassword("$$Mas7eR");
        
        if (!db.open()) qDebug() << db.lastError().text();
        
        else {
            qDebug() << "Success!";
            db.close();
        }
        return a.exec();
    }
    

    Output is:
    [MySQL][ODBC 8.0(w) Driver] Can't connect to MySQL server on 'localhost' (10061) QODBC3: Unable to connect"

    I'm a bit confused why is it claiming for localhost if I setup 192.168.1.200
    Any help?.. Thanks so much in advance.


    Update :
    I have noticed that setPort and setUserName had no effect, is more like those values are being overwritten from somewhere... that's why output points to localhost rather than server ip.... I say this because I have tested the same example on the server itself with loopback and worked, then changed the setHostName to 10.0.1.1 (a random ip) and worked again.. ...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I am by no means an ODBC expert but I think you have to pass that information through the connection string.

      See here.

      It's also explained in the Qt ODBC driver documentation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • U Offline
        U Offline
        U7Development
        wrote on last edited by
        #3

        you're absolutely right,... this is the string that worked for me:

        QString connection_string = 
        "Driver={MySQL ODBC 8.0 Unicode Driver};"
        "Server=192.168.1.200, 3306;"
        "Database=db0;"
        "Uid=root;"
        "Pwd=$$Mas7eR";
        "MULTI_HOST=1;");
        
        db.setDatabaseName(connection_string);
        

        Thanks.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Great !

          Then please mark the thread as solved so other forum members may know a solution has been found :-)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved