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. Qt5 MYSQL “open()” method return true even with wrong credentials
Forum Updated to NodeBB v4.3 + New Features

Qt5 MYSQL “open()” method return true even with wrong credentials

Scheduled Pinned Locked Moved General and Desktop
qt5.5qmysql
5 Posts 2 Posters 1.7k Views 2 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.
  • K Offline
    K Offline
    Krakusekpl
    wrote on last edited by
    #1

    While writing a Qt5 application that uses QSqlDatabase with MySQL, I encountered a strange behavior when I try to connect to datebase. QSqlDatabase::open() returns true even with wrong username, password and port. That's my code:

    QSqlDatabase DB = QSqlDatabase::addDatabase("QMYSQL", "Connection");
    DB.setHostName(Interface.InputIP->text());
    DB.setDatabaseName("connectdb");
    DB.setPort(Interface.InputPort->value());
    DB.setUserName(Interface.InputLog->text());
    DB.setPassword(Interface.InputPass->text());
    bool result = DB.open();
    if(result)
    	QMessageBox::information(0, "Success", "Connected");
    else
    	QMessageBox::information(0, "Error", DB.lastError().text());
    DB.close();
    

    What can be the reason?

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

      Hi and welcome to devnet,

      Just a silly idea but, are you sure the database you are accessing is protected ?

      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
      • K Offline
        K Offline
        Krakusekpl
        wrote on last edited by
        #3

        I'll write differently.
        If i write all credentials correctly i can connect to database, and method "open" return true which is proper behavior.
        But, if i write all credentials incorrectly (without IP) or i try to connect to disabled database method "open" again return true.
        If I use external application to connect to my database and it's works perfectly.

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

          Did you close the connection first ?

          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
          • K Offline
            K Offline
            Krakusekpl
            wrote on last edited by Krakusekpl
            #5

            No, I close connection after try to connect and after conditional statement, as it is in the code in first post.

            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