Hi all.
Please I need to help with db pool. We running our application and database on Bluemix. We have node.js application connecting to DB2. We are using express server.
Everything is working fine on local (with the same db as DEV space), also the code is working fine on our DEV (it has its own DB instance) and TEST space(it has its own db instance) in Bluemix.
ONLY in PROD space (of course it has its own db instance) it is NOT WORKING !!!
I found the problem is in pool.init command or pool.open command.
In shared module connectionPool.js I have following code ->
let ibmdb = require('ibm_db');
var Pool = require("ibm_db").Pool;
var pool = new Pool();
pool.init(5, dsnString); //dsnString contains connection string to db
module.exports = dbConnection => {
pool.open(dsnString, (err, conn) => {
if (err) {console.log(' === DATABASE POOL ERROR: init/open error ===');}
dbConnection(conn);
});
};
and calling this in other modules like this ->
let connPool = require('../../connectionPool');
app.get('/some_url', (req, res) => {
let sql = `SELECT * FROM TEST`;
connPool(conn => {
conn.query(sql, (err,data) => {
if (err) {console.log(err);
} else {
return res.render('someview', {results: data});
}
conn.close();
});
});
});
The code in PROD space is not going through pool.init(5, dsnString); line if its there , or its not going through this line: pool.open(dsnString, (err, conn);
if I remove line: pool.init(5, dsnString);
in both cases I am not getting any error message, the code just stop there waiting for something.
Again, strange thing is that this code is working in any variant on local and also in dev and test space.
The ONLY DIFFERENCE is that for local, and for Bluemix dev and test space we are using DB2 in version: EnterpriseTransactional2.8.500
and for production we have different version: EnterpriseTransactionalHA12.128.1400
Previously I was using following code to connect DB2 (which was working perfectly in all environments: local, dev, test and also in PROD!!!),:
- in shared module: connection.js I was connecting to db ->
...
var db = ibmdb.openSync(dsnString); //dsnString contains connection string to db
if (db.connected) {console.log('Application connected to database.');}
module.exports = db2creds;
module.exports = db;
- and in code I was calling exported db ->
var db = require('./connection');
app.get('/some_url', (req, res) => {
let sql = "SELECT * FROM TEST";
db.query(sql, (err,data) => {
if (err) {console.log(err);
} else {
return res.render('suser', {results: data});
}
});
});
I will appreciate any help, as I don't know now if the problem is in different env setting for those two diff databases or where the problem is.
Thank you in advance
Martin