Cannot enqueue Query after fatal error - connection with mysql

919 views
Skip to first unread message

Mitesh Shah

unread,
Mar 5, 2017, 9:13:59 PM3/5/17
to nodejs

Hi I am new to nodejs and trying the connect the Mysql. 
I am really troubled with the error Cannot enqueue Query after fatal error.
a) I am not using connection pooling so as not to complicate for start.
b) I had written connection.connect() at the start of code but removed it as I read in a link that it is not required. (refer below link)
Cannot enqueue Handshake after invoking quit

Below is the format for all my queries.


function matchFirstName(person_name){
              var query = "select firstName,lastname, username,securityRole from users where firstName='"+person_name+"'" ;
              connection.query(, 
                function (err, rows) {
                    if (err || rows.length === 0) {
                        if(err){
                            console.log("error " + err);                
                            connection.end();
                        }
                    }
                    else{  
                        // some code or call to a different function which too might call a query in the same manner
                    }
            });
        }



Someone please suggest a permanent solution to this. 
I have tried removing connection.end() from my code as well but that too didnt help. This error pops up suddenly.
Reply all
Reply to author
Forward
0 new messages