Closed anonprophet closed 9 years ago
im fixed this using connection pool remove .connect() & . end()
and using .release
I have same problem although I am not using .connect() & . end()
.
Anyone help me? Thanks
I think use pooling
is the best way
For example:
var pool = mysql.createPool({
connectionLimit : 10, // default = 10
host : 'localhost',
user : 'root',
password : 'kensxxx',
database : 'fbtool'
});
router.get('/test/query', function (req, res) {
pool.getConnection(function (err, connection) {
connection.query("SELECT * FROM tblcomment", function (err, rows) {
connection.release();
if (err) throw err;
console.log(rows.length);
res.send(JSON.stringify(rows));
});
});
});
Hi @MrKenitvnn , Still not working with me :( . Any way help me check it?
I had the same issue on my end and I resolve it by removing
connection.connect(); and connection.end();
Hey guys Use mysql.createPool instead of mysql.createConnection to set up teh conenction and use connection.release to end connections.
This error happens when you have multiple queries running through the program and the connections aren't closed properly after the query is resolved.
-> I resolve this so that every time after connecting to the DB (Query etc.) I close the connection using this function: (The function terminates the connection and creates the connection again)
function endCon(){ db.end( function(err) { if (err) {console.log("Error ending the connection:",err);}
db = mysql.createConnection({
host: 'localhost',
user: 'your_user',
password: 'your_psw',
database: 'your_DB'
});
});
}
its work fine, then when after a condition when try to call
reloadQuestion
again its got erroralready try to remove
connection.end();
but the problem still