Okay all, for whatever reason I can't seem to get my synapse to cooperate.
I am usually better at reading, following directions, and trouble-shooting,
but I recognize that continuing to beat my head against the desk is serving
no purpose, and help is necessary.
I am trying to do one thing in two parts. Part one is create a node.js
connection, using odbc, to my IBM i development partition, from my PC.
Then, once that is working, take the same code (or slighly modified as
necessary) and put in in the IFS and run it natively.
Background, I started with this page,
https://github.com/IBM/ibmi-oss-examples/blob/master/odbc/odbc.md. The
driver is successfully installed from the ACS download page, on my IBM i.
When I run "odbcinst -j" I have:
unixODBC 2.3.4
DRIVERS............: /QOpenSys/etc/odbcinst.ini
SYSTEM DATA SOURCES: /QOpenSys/etc/odbc.ini
FILE DATA SOURCES..: /QOpenSys/etc/ODBCDataSources
USER DATA SOURCES..: /home/MEISINS/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
There is no user .odbc.ini file in my folder.
The odbcinst.ini file reads:
[IBM i Access ODBC Driver]
Description=IBM i Access ODBC Driver
Driver=/QOpenSys/pkgs/lib/libcwbodbc.so
Threading=0
DontDLClose=1
UsageCount=1
And then the odbc.ini file reads:
### IBM provided DSN - do not remove this line ###
[*LOCAL]
Description = Default IBM i local database
Driver = IBM i Access ODBC Driver
System = localhost
UserID = *CURRENT
### Start of DSN customization
[systemnameDSN]
Description = Default IBM i remote access to database
Driver = IBM i Access ODBC Driver
System = systemname.domainname.com
UserID = username
Password = userpassword
### End of DSN customization
### IBM provided DSN - do not remove this line ###
Yes, I added the systemnameDSN, though, I have seen no difference with or
without it, and I see no way that I can access it from off-platform.
My app.js file that I created tried using both the above link examples and
this also:
https://dev.to/moyarich/how-to-connect-node-js-to-ibm-db2-database-16m6
When I execute the code below on my PC, it returns both the physical data,
and the columnar meta-data for the table.
/*jshint esversion: 6 */
const odbc = require('odbc');
const cn = "DRIVER=IBM i Access ODBC
Driver;SYSTEM=systemname;UID=username;PWD=userpassword";
odbc.connect(cn , (error, connection) => {
if (error) {
throw error;
}
connection.query('SELECT * FROM myschema.mytable', (error, result) => {
if (error) {
throw error;
}
console.log(result);
}
);
});
Obviously, I would prefere not to have to store my UID and PWD inside the
.js file, if possible.
Once I bring the code to the IBM i IFS, the only change I made was to remove
the "const cn" line and change the odbc.connect to have 'DSN=*LOCAL' in
place of the cn. When I execute the file, either with "node app.js" or just
run the file, it sits there and does nothing.
My package.json in the IFS folder, contains this:
"dependencies": {
"express": "^4.17.1",
"odbc": "^2.3.0",
"path": "^0.12.7"
}
So, I think I have what I need there installed via npm.
I am sure I've done something really silly. Of course, I'd like to be able
to have the ability to create my project on my PC (only connecting when
neeeding to test) and then just copy the code to the IFS with as little
change to the code as possible.
As always, any and all help is greatly appreciated.
Thanks,
Steve Meisinger
As an Amazon Associate we earn from qualifying purchases.