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(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.
Update: I think I found the reason. First some query that I use (a query which normally works) gives a ETIMEDOUT issue and then every following query fails. I increased the connectTimeout from 60000 to 120000 ms and added the following code.
connection.on('error', function (err){
if(err.code === 'ETIMEDOUT' ){
connection.connect();
}
});
Will this solve my problem?