Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.
QtWS25 Last Chance

The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
10 Posts 4 Posters 623 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.
  • J Offline
    J Offline
    Jeferson
    wrote on 25 Sept 2024, 12:37 last edited by
    #1

    Hello, my problem is that when I create the setup, but when I install it on a second Windows 64 computer, it does not recognize the MySQL connection.

    On my computer where I created the project, it works fine and recognizes the MySQL connection.

    What I did:

    1- Build the project in Realese.

    2- I transferred the necessary data to the Realese folder using Windows EmbedLoyqt.exe.

    3- I manually placed the libmysql.dll file in the same folder as the executable.

    4- I authorized remote access on my server from my computer and from a second computer;

    5- When I installed it on the second computer, I checked all the files and folders, and they were all transferred without problems, that is, the same ones that are in the Realese folder are also installed on the second computer.

    I tested it on my computer and everything works fine, but on a second computer it does not recognize the connection.
    The installation on the second computer was successful, but when I run the username and password, it does not recognize the connection.
    Another piece of information is that when I manually remove the libmysql.dll file from the executable folder, the same error occurs on my computer as on the second computer, but in this case I do not remove the libmysql file from the second computer.
    Could you please help me?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ankou29666
      wrote on 25 Sept 2024, 13:00 last edited by
      #2

      Hi.

      Is the MySql database located on the first computer ? or on a third one ? Is the database reachable by the second computer ?
      What error message do you get exactly ? what do you mean when you say the connection is not "recognized" ?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jeferson
        wrote on 25 Sept 2024, 14:13 last edited by
        #3

        Hi.
        I have a local connection using XAMPP and the connection to the MySQL database works fine for the moment I'm developing, but that's not the one I'm talking about.

        The database I'm talking about is on my Hostgator server, where I put my projects to be online.

        And there I also have the MySQL database, that's the one I'm talking about, in fact I've already authorized my computer and the second computer for a remote connection, as I mentioned before. But only the computer where I developed the project can connect. When I install it on the second computer, it doesn't recognize the connection to the database.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jeferson
          wrote on 25 Sept 2024, 14:23 last edited by
          #4

          I created and installed the setup on both computers.
          I created a login system, and I can log in with my computer, which I use to develop the project, that is, it recognizes the username and password, but when I log in with the second computer, it gives me an error message that it does not recognize the connection to the database.

          A 1 Reply Last reply 25 Sept 2024, 14:53
          0
          • A Offline
            A Offline
            artwaw
            wrote on 25 Sept 2024, 14:34 last edited by
            #5

            Please post your connection setup code?

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • J Jeferson
              25 Sept 2024, 14:23

              I created and installed the setup on both computers.
              I created a login system, and I can log in with my computer, which I use to develop the project, that is, it recognizes the username and password, but when I log in with the second computer, it gives me an error message that it does not recognize the connection to the database.

              A Offline
              A Offline
              ankou29666
              wrote on 25 Sept 2024, 14:53 last edited by
              #6

              @Jeferson said in The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.:

              I created and installed the setup on both computers.
              I created a login system, and I can log in with my computer, which I use to develop the project, that is, it recognizes the username and password, but when I log in with the second computer, it gives me an error message that it does not recognize the connection to the database.

              What do you mean by "recognize the connection" ? What is the error message ?
              Is this unknown host ? wrong credentials ? unreachable address ? port closed ? Anything else ?

              1 Reply Last reply
              3
              • J Offline
                J Offline
                Jeferson
                wrote on 25 Sept 2024, 16:13 last edited by
                #7

                DbManager& DbManager::getInstance() {
                static DbManager instance;
                return instance;
                }

                DbManager::DbManager() {
                db = QSqlDatabase::addDatabase("QMYSQL");

                db.setHostName("localhost");
                db.setDatabaseName("DbName");
                db.setUserName("root");
                db.setPassword("");
                db.setConnectOptions("CLIENT_SSL=1");
                

                }

                bool DbManager::connect() {
                if (!db.open()) {

                    qDebug() << "Available Drivers:" << QSqlDatabase::drivers();
                      QMessageBox::critical(nullptr, "Erro", "Error connecting to database: " + db.lastError().text());
                    return false;
                }
                return true;
                

                }

                QSqlDatabase DbManager::getDatabase() {
                return db;
                }

                bool DbManager::supportsTransactions() const {
                QSqlDatabase db = QSqlDatabase::database();
                if (!db.driver()->hasFeature(QSqlDriver::Transactions)) {
                QMessageBox::critical(nullptr, "Erro", "Erro");
                return false;
                }
                return true;
                }

                A 1 Reply Last reply 25 Sept 2024, 17:14
                0
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 25 Sept 2024, 16:40 last edited by
                  #8

                  And who should be able to read this and what error do you get?
                  Please format your code with the code tags (</>).
                  Also make sure to deploy all dependencies as described here: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows

                  "When you distribute your application, remember to include libmysql.dll / libmariadb.dll in your installation package. It must be placed in the same folder as the application executable. libmysql.dll additionally needs the MSVC runtime libraries which can be installed with vcredist.exe"

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • J Jeferson
                    25 Sept 2024, 16:13

                    DbManager& DbManager::getInstance() {
                    static DbManager instance;
                    return instance;
                    }

                    DbManager::DbManager() {
                    db = QSqlDatabase::addDatabase("QMYSQL");

                    db.setHostName("localhost");
                    db.setDatabaseName("DbName");
                    db.setUserName("root");
                    db.setPassword("");
                    db.setConnectOptions("CLIENT_SSL=1");
                    

                    }

                    bool DbManager::connect() {
                    if (!db.open()) {

                        qDebug() << "Available Drivers:" << QSqlDatabase::drivers();
                          QMessageBox::critical(nullptr, "Erro", "Error connecting to database: " + db.lastError().text());
                        return false;
                    }
                    return true;
                    

                    }

                    QSqlDatabase DbManager::getDatabase() {
                    return db;
                    }

                    bool DbManager::supportsTransactions() const {
                    QSqlDatabase db = QSqlDatabase::database();
                    if (!db.driver()->hasFeature(QSqlDriver::Transactions)) {
                    QMessageBox::critical(nullptr, "Erro", "Erro");
                    return false;
                    }
                    return true;
                    }

                    A Offline
                    A Offline
                    ankou29666
                    wrote on 25 Sept 2024, 17:14 last edited by ankou29666
                    #9

                    @Jeferson said in The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.:

                    db.setHostName("localhost");

                    Yep ... There is the problem ...

                    The problem is that when you try to connect to localhost, you try to establish connection with a service that is located on the very same machine. This is the reason why your app connects to the DB on the first machine and not on the second one.
                    Because your app on the second computer tries to access to the database on the second computer itself, while your DB runs on the first computer. So for sure there's no risk for the connection to succeed.

                    If you want your second computer to access the DB on the first machine, you have to call the address of the first computer, not localhost.

                    1 Reply Last reply
                    1
                    • A Offline
                      A Offline
                      artwaw
                      wrote on 25 Sept 2024, 18:00 last edited by
                      #10

                      Like @ankou29666 said.

                      I have a separate question though: you really have a free floating mysql on the internet with root access enabled?

                      For more information please re-read.

                      Kind Regards,
                      Artur

                      1 Reply Last reply
                      0

                      7/10

                      25 Sept 2024, 16:13

                      • Login

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