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. QT Remote Database
Forum Updated to NodeBB v4.3 + New Features

QT Remote Database

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 5.1k Views 3 Watching
  • 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.
  • L Offline
    L Offline
    leonidas_lolo
    wrote on last edited by
    #3

    Yes the IP/port values are correct, and I have a firewall.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #4

      are you able to connect to the remote database from the standard MySQL client? try to disable the firewall

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leonidas_lolo
        wrote on last edited by
        #5

        Yes i can connect to remote database from the standard MySQL client. I also disabled the firewall and it gives me the same error.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #6

          Can you post the code??

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leonidas_lolo
            wrote on last edited by leonidas_lolo
            #7

            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";
            }

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #8

              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";
              }
              
              

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • L Offline
                L Offline
                leonidas_lolo
                wrote on last edited by leonidas_lolo
                #9

                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.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leonidas_lolo
                  wrote on last edited by
                  #10

                  it's not 'QODBC'. its 'ODBC'. Sorry writing mistake.

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

                    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.

                    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
                    • L Offline
                      L Offline
                      leonidas_lolo
                      wrote on last edited by
                      #12

                      I enabled remote access on MySQL server and everything worked fine. Thanks fro your help guys.

                      J 1 Reply Last reply
                      0
                      • L leonidas_lolo

                        I enabled remote access on MySQL server and everything worked fine. Thanks fro your help guys.

                        J Offline
                        J Offline
                        jalomic
                        wrote on last edited by
                        #13

                        @leonidas_lolo Mark this topic as "Solved" please

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          leonidas_lolo
                          wrote on last edited by
                          #14

                          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.

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

                            If you don't have the option in the "Topic Tool" button, then the good old "edit the title and prepend [solved]" will do :)

                            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
                            0

                            • Login

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