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. [SOLVED]QMYSQL: Unable to Connect
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QMYSQL: Unable to Connect

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 9.1k Views 1 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.
  • N Offline
    N Offline
    Nicolasllk
    wrote on 2 Jul 2013, 12:34 last edited by
    #1

    Hello everyon, first of all i want to say sorry if my english is not polished enought. Having said that i`ll explain my problem starting with a little background.
    I am coding an app that (among others stuff) connects to a remote (and local, but it is not giving me problems) MySQL database in order to make some inserts. Initially the app was a single threaded aplication but some how the database connection process hanged for several seconds (even minutes somtimes) freezing the ui during that time.
    The solution was to move that class to a separate thread, which i did, the freezing problem was solved but i came through this problem which so far couldnt find an specific answer/solution and now the connection process is throwing the following error:
    Lost connection to MySQL server at 'reading initial communication packet', system error: 4 QMYSQL: unable to connect
    The thing is that if i go back to the single threaded solution, the app may freeze but eventually I get connected to the Database.
    My code is as follows:

    @void db_comm::run(){
    db = QSqlDatabase::addDatabase("QMYSQL","remote");
    db.setHostName(remoteHost);
    db.setPort(remotePort);
    db.setDatabaseName(remoteDbName);
    db.setUserName(remoteUser);
    db.setPassword(remotePassword);

        if(db.open()){           
            remoteConnected=true;
            emit dbRemoteConnected(true);
        }else{
            emit dbRemoteConnected(false);
            qDebug()<<"Fallo en la conexion a la base de datos remota: "+db.lastError().text();            
            remoteConnected=false;
            remoteErr++;
        }   
    

    }@

    The class containing this method is defined as follows:
    @class db_comm : public QThread
    {
    Q_OBJECT
    ..
    ..
    ..@

    So when i try to connect to the remote database I call the start() method.
    Surely i am doing something wrong but i dont know what. Thanks in advance.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      francescmm
      wrote on 2 Jul 2013, 15:15 last edited by
      #2

      I look at Google this issue and I have found 2 posts with same reference:

      "Initial System Error":http://stackoverflow.com/questions/11168945/mysql-server-at-reading-initial-communication-packet-system-error-111

      and

      "How to solve it...":http://www.bramschoenmakers.nl/en/node/595

      Can try with modify the permissions of MySql?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nicolasllk
        wrote on 2 Jul 2013, 15:30 last edited by
        #3

        francescmm, thanks for the reply. I seen them already, unfortunately MySQL configuration is not the problem, in fact I am running another aplication (java) that is connecting to the same database with identical connection configuration (user, password, host, port,etc) with no problems.
        I think if it where a configuration problem the same (or similar) issue would occur in both applications. I also tried to connect to mysql using the console with no problems as well.

        BTW I am using Ubuntu linux 12.04 32bits, Mysql server 5 and Qt 4.8.1.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          francescmm
          wrote on 2 Jul 2013, 16:36 last edited by
          #4

          What is the return of QSqlDatabase::isValid() ?
          In addition to I say above, can you report the errorId (it is using db.lastError().number();) ?

          Thanks a lot!

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Nicolasllk
            wrote on 2 Jul 2013, 18:29 last edited by
            #5

            QSqlDatabase::isValid() reports TRUE, and db.lastError().number() reports: 2013

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Nicolasllk
              wrote on 2 Jul 2013, 18:30 last edited by
              #6

              Podriamos hablar en castellano no? :P jejeje

              1 Reply Last reply
              0
              • F Offline
                F Offline
                francescmm
                wrote on 2 Jul 2013, 19:03 last edited by
                #7

                Yes! But not there! ;)

                All you have written seems good, so I cannot say what is wrong. Mmmmm... coud you send me a test user to try from my host? (Send me by private on my profile)

                [quote author="Nicolasllk" date="1372789834"]Podriamos hablar en castellano no? :P jejeje[/quote]

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  Nicolasllk
                  wrote on 5 Jul 2013, 12:14 last edited by
                  #8

                  Hello there!, Somehow i manage to "solve" the issue. Aparently something (I havent discover which module yet) was interrupting the database connection/authentication process. Sorry francescmm, but I cant provide with more code than I gave above (commpany politic and privacy stuff). Anyway, thank you a lot for posting, much appreciated :D.
                  See you around.

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    francescmm
                    wrote on 5 Jul 2013, 13:33 last edited by
                    #9

                    Next time take into account the MySQL error code! Some times it clarify us! :)

                    1 Reply Last reply
                    0

                    1/9

                    2 Jul 2013, 12:34

                    • Login

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