[MySQL][ODBC 8.0(w) Driver] Can't connect to MySQL server on 'localhost' (10061) QODBC3: Unable to connect"
-
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.. ... -
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.
-
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.
-
Great !
Then please mark the thread as solved so other forum members may know a solution has been found :-)