Reputation: 211
I've followed the instructions: https://www.ibm.com/developerworks/community/blogs/pd/entry/using_ibm_db2_from_node_js4?maxresults=15&page=0&lang=en for a 32-bit install of Ubuntu.
It seems to have installed correctly and I can run require('ibm_db'). Using the sample code provided (nodedb2test.js), no matter what database parameters I use I get the error:
node nodedb2test.js
Test program to access DB2 sample database
*** stack smashing detected ***: node terminated
Aborted (core dumped)
Heres the sample code:
/*require the ibm_db module*/
var ibmdb = require('ibm_db');
console.log("Test program to access DB2 sample database");
ibmdb.open("DRIVER={DB2};DATABASE=testdb;UID=username;PWD=password;HOSTNAME=localhost;port=3000", function(err, conn)
{
if(err) {
console.error("error: ", err.message);
}
});
Also I looks the version of DB2 I need to connect to is version 6. I have installed BM Data Server Driver version 10.5, does this correspond to the version of DB2? It appears below v9.1 drivers are not available.
Upvotes: 1
Views: 6994
Reputation: 1409
At time of writing this works for me.
C:\Development\Javascript>node -p "process.arch" x64
C:\Development\Javascript>node -p "process.platform" win32
C:\Development\Javascript>node -p "process.version" v14.17.5
C:\Development\Javascript>npm install ibm_db
var ibmdb = require("ibm_db");
const config = require("config");
const hostname = config.get("db2.hostname");
const username = config.get("db2.username");
const password = config.get("db2.password");
ibmdb.open("DRIVER={DB2};DATABASE=bludb;HOSTNAME=" + hostname + ";UID=" + username + ";PWD=" + password + ";PORT=31198;PROTOCOL=TCPIP;SECURITY=SSL", function (err, conn){
if (err) return console.log(err);
conn.query("SELECT * FROM orders", function (err, data) {
if (err) console.log(err);
console.log(data);
conn.close(function () {
console.log('done');
});
});
});
Upvotes: 1
Reputation: 409
We can use ibm_db without installing IBM Data Server Driver Package too. ibm_db internally uses DB2 V10.5FP5 ODBC/CLI driver to talk to DB2 server. Please share the platform info and OS version where you have installed ibm_db. In june'14, ibm_db was supported on Linuxppc, AIX and zLinux platforms, but latest release is supporting. If latest driver is not working for you, please open an issue on github.com/ibmdb/node-ibm_db/issues/new
. Thanks.
Upvotes: 0