IBM / nodejs-idb-pconnector

Promise-based Db2 Connector for IBM i
MIT License
28 stars 18 forks source link

Example code does not work #36

Closed worksofliam closed 5 years ago

worksofliam commented 5 years ago

Hi

I have tried using the examples out of pconnector and the regular connector, but both return with the same error.

const {dbconn, dbstmt} = require('idb-connector');
const sSql = 'SELECT STATE FROM QIWS.QCUSTCDT';
const connection = new dbconn();
connection.conn("*LOCAL");
const statement = new dbstmt(connection);

statement.exec(sSql, (x) => {
  console.log("%s", JSON.stringify(x));
  statement.close();
  connection.disconn();
  connection.close();
});

Gives me:

ERROR: SQLALLOCENV(1)/home/ALAN3/prod_demo/test.js:5
const statement = new dbstmt(connection);
                  ^

Error: SQLSTATE=PAERR SQLCODE=8013 The Dbconn Object is not connected
    at Object.<anonymous> (/home/ALAN3/prod_demo/test.js:5:19)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

The pconnector gives me:

ERROR: SQLALLOCENV(1)Example app listening on port 9123!

Any initial ideas what the issue could be? If these examples are supposed to be working, what can I check on my system to determine the issue. I am using Node.js 10.15.0 and I am on IBM i 7.3.

abmusse commented 5 years ago

Hey Liam,

Looks to me the error originates here while allocating the environment.

SQL_ERROR was returned you can read more on SQLAllocEnv

Without an environment handle allocated connections and statements wont work.

What version of idb-connector do you have installed?

Can you provide the code snippet you used with the idb-pconnector?

I tried running the example above with idb-connector on 7.3 with node 10.15.0 and it was successful

worksofliam commented 5 years ago

Hey @abmusse

Below is the example code for the idb-pconnector, but gives the same error as idb-connector.


const moment = require('moment');
const { Connection, Statement } = require('idb-pconnector');
const connection = new Connection({ url: '*LOCAL' });

module.exports = function(app) {
  app.get('/customer', async function(req, res) {

    const statement = new Statement(connection);
    const results = await statement.exec('SELECT CUSNUM FROM QIWS.QCUSTCDT');
    statement.close();

    res.json(results);
  });
}
ERROR: SQLALLOCENV(1)Example app listening on port 9123!
worksofliam commented 5 years ago

This issue has been resolved. It was happening because the following symlinks were overwritten to be true files:

This happens when someone attempts to build db2sock.

These files should really be symlinks which point to /QOpenSys/QIBM/ProdData/OS400/PASE/lib/libdb400.a

Running the following commands fixed this the issue and the script is now running:

bash-4.4$ mv libdb400.a libdb400.a.bak
bash-4.4$ ls libdb400*
libdb400.a.bak  libdb400.a.prod  libdb400.exp
bash-4.4$ ln -s /QOpenSys/QIBM/ProdData/OS400/PASE/lib/libdb400.a libdb400.a
bash-4.4$ ls libdb400*
libdb400.a  libdb400.a.bak  libdb400.a.prod  libdb400.exp
kadler commented 5 years ago

Friends don't let friends use db2sock :wink:

GautierFR commented 4 years ago

Hi, I obtain the same error with my nodejs12 "chrooted" environnement (with ibmichroot). I think the problem concerns the libdb400.a too, but in my chroot environnement, I don't have access to the /QOpenSys/QIBM/xxx subfolders (principle of my chroot jail).

In my jail, /usr/lib/libdb400.a and /QOpenSys/usr/lib/libdb400.a are real files (no symlink). Do you know how I can solve that ?

ThePrez commented 4 years ago

@GautierFR , does /QOpenSys/QIBM/ProdData/OS400/PASE/lib/libdb400.a exist in your chroot? Also, how did you create your chroot environment?

Please open a fresh issue so we can route and handle accordingly. Remediation might differ for your chroot case.

GautierFR commented 4 years ago

@ThePrez Ok, thank you. I created a new issue on idb-connector project : https://github.com/IBM/nodejs-idb-connector/issues/125