I am trying to setup connection pool and wants to release the connection once done with query.
How I am implementing:
dbConnection.getConnection( function(err, connection){
dbConnection.release();
if (err) {
console.log("db error ", err);
return callback(err);
//connection.release();
}else {
var memberId= member.member_id;
return dbConnection.query("Select * from tableName, function(err, result,fields){
if (err) {
return callback(err);
}else {
return callback(null, result);
}
});
}
dbConnection.on('error', function(err) {
console.log("db on error ");
callback(err);
return;
});
I am getting the error:
TypeError: dbConnection.release is not a function
at Query._callback (/home/itstym/node_js/perb/models/member.js:26:22)
at Query.Sequence.end (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
at Query._handleFinalResultPacket (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
at Query.EofPacket (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/sequences/Query.js:123:8)
at Protocol._parsePacket (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/itstym/node_js/perb/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
But I have gone through numerous example available on internet, all are doing the same thing. Do I am missing something?
dbconnection.js
var dbconnection = mysql.createPool({
connectionLimit : 10, //important
host:'localhost',
user:'root',
database:'perb',
password: 'dbandc',
debug : false
});
module.exports=dbconnection;
I am trying to setup connection pool and wants to release the connection once done with query.
How I am implementing:
dbConnection.getConnection( function(err, connection){
dbConnection.release();
if (err) {
console.log("db error ", err);
return callback(err);
//connection.release();
}else {
var memberId= member.member_id;
return dbConnection.query("Select * from tableName, function(err, result,fields){
if (err) {
return callback(err);
}else {
return callback(null, result);
}
});
}
dbConnection.on('error', function(err) {
console.log("db on error ");
callback(err);
return;
});
I am getting the error:
TypeError: dbConnection.release is not a function
at Query._callback (/home/itstym/node_js/perb/models/member.js:26:22)
at Query.Sequence.end (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
at Query._handleFinalResultPacket (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
at Query.EofPacket (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/sequences/Query.js:123:8)
at Protocol._parsePacket (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/itstym/node_js/perb/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/itstym/node_js/perb/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
But I have gone through numerous example available on internet, all are doing the same thing. Do I am missing something?
dbconnection.js
var dbconnection = mysql.createPool({
connectionLimit : 10, //important
host:'localhost',
user:'root',
database:'perb',
password: 'dbandc',
debug : false
});
module.exports=dbconnection;
Share
Improve this question
asked Dec 27, 2017 at 10:56
Ankur_009Ankur_009
3,7304 gold badges32 silver badges50 bronze badges
2 Answers
Reset to default 4You want to call release()
on the connection variable passed from the callback, not on the pool itself. The first 2 lines should instead be:
dbConnection.getConnection( function(err, connection){
connection.release();
I basically just changed dbConnection
to connection
on line 3.
Please use connection.release()
instead of dbConnection.release();
please refer https://www.npmjs./package/mysql#pooling-connections