QT Remote Database
-
[SOLVED]
Hello guys,
I am new in QT and I need some help. I want to get access and manipulate the data into a database at (xxx.xxx.xxx.xxx). I can connect to my localhost database, but when I try to connect to a remote database I get this error from db.lasterror() "Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' <10060 "Unknown error "> QMYSQL: Unable to Connect.I am running Windows XP. I can connect to the database on (xxx.xxx.xxx.xxx) from browser.
Please tell me what should I do.
Thank you in advance. -
Yes the IP/port values are correct, and I have a firewall.
-
Yes i can connect to remote database from the standard MySQL client. I also disabled the firewall and it gives me the same error.
-
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
void connectToDatabase(QString Hostname,unsigned int Port,QString Username,QString Password,QString Database);int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
connectToDatabase("xxx.xxx.xxx.xxx",3306,"myusername","mypassword","mydatabase");
qDebug() << "Database closed";
db.close();
return a.exec();
}void connectToDatabase(QString Hostname,unsigned int Port,QString Username,QString Password,QString Database) {
db.setHostName(Hostname);
db.setPort(Port);
db.setUserName(Username);
db.setPassword(Password);
db.setDatabaseName(Database);
if(!db.open()) {
qDebug() << "Error opening database!";
qDebug() << db.lastError().text();
}
else
qDebug() << "Connection with database genikoeo is established!\n";
} -
Seems the driver is correctly loaded.
The problem could be related to the global db object;can you re-write in this way?
void connectToDatabase(QString Hostname,unsigned int Port,QString Username,QString Password,QString Database); int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); connectToDatabase("xxx.xxx.xxx.xxx",3306,"myusername","mypassword","mydatabase"); qDebug() << "Database closed"; db.close(); return a.exec(); } void connectToDatabase(QString Hostname,unsigned int Port,QString Username,QString Password,QString Database) { QSqlDatabase db = QSqlDatabase::database(); db.setHostName(Hostname); db.setPort(Port); db.setUserName(Username); db.setPassword(Password); db.setDatabaseName(Database); if(!db.open()) { qDebug() << "Error opening database!"; qDebug() << db.lastError().text(); } else qDebug() << "Connection with database genikoeo is established!\n"; }
-
it says :
QSqlDatabasePrivate::database: unable to open database: "Access denied for user 'ODBC'@'localhost' <using password:NO> QMYSQL: unable to connect"
and after that it gives me the same previous error: "Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' <10060 "Unknown error "> QMYSQL: Unable to Connect. -
it's not 'QODBC'. its 'ODBC'. Sorry writing mistake.
-
Hi,
Did you configure your database to be accessible from outside ?
Accessing it from your web browser just says that your remote admin can access the local database not that remote access is working correctly.
-
I enabled remote access on MySQL server and everything worked fine. Thanks fro your help guys.
-
I enabled remote access on MySQL server and everything worked fine. Thanks fro your help guys.
@leonidas_lolo Mark this topic as "Solved" please
-
Can you please tell me how to do that. This is my first forum conversation and I don't know how to do that. Thanks.
-
If you don't have the option in the "Topic Tool" button, then the good old "edit the title and prepend [solved]" will do :)