[SOLVED]QMYSQL: Unable to Connect



  • 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.



  • 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?



  • 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.



  • 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!



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



  • Podriamos hablar en castellano no? :P jejeje



  • 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]



  • 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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.