Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code: -2004 Msg: Can't initialize DBCAPI #46

Open
redevill opened this issue Mar 23, 2022 · 11 comments
Open

Code: -2004 Msg: Can't initialize DBCAPI #46

redevill opened this issue Mar 23, 2022 · 11 comments

Comments

@redevill
Copy link

Trying to use this Driver to connect from a Nodejs server (hosted on macOS 10.15.7) to a remote Sql Anywhere 17 "SQL Anywhere Network Server Version 17.0.4.2053" database, hosted on a Windows box. With 2638 port open on the Firewall.

Readings done suggest that I need Sql Anywhere Client on my Mac...
(However - the node-sqlanywhere readme, does not say this is a requirement)

Is a SA client needed? If so, where might I get a client?
Any help appreciated.
Thanks

@DanCummins-SAP
Copy link
Contributor

Hello,

The download of the client can be found here:
https://wiki.scn.sap.com/wiki/plugins/servlet/mobile?contentId=448478814#content/view/448478814

Direct link: https://d5d4ifzqzkhwt.cloudfront.net/sqla17client/sqla17_client_os_x.tar.gz

The "DBCAPI" library on macOS is libdbcapi_r.dylib.

Set SQLANY_API_DLL to point to it, eg.
export SQLANY_API_DLL=/Applications/SQLAnywhere17/System/lib64/libdbcapi_r.dylib

Add dependent libraries to library path:
source /Applications/SQLAnywhere17/System/bin64/sa_config.sh

HTH,
Dan

@redevill
Copy link
Author

redevill commented Mar 24, 2022

Thank you so much for the response... will give it a go.
It would be very helpful, to note the need of the above prerequisite on main Readme.

"This driver communicates with the native SQL Anywhere libraries, and thus requires native compilation. Native compilation is managed by [node-gyp]"

This statement implied to me, that needed SQL Anywhere libraries were compiled and installed as part of the "npm install", and the only the compilation ability (and related compiler code) was a pre-requisite.
Thank you.

@redevill
Copy link
Author

redevill commented Mar 28, 2022

So - From my Mac, I can no do a dbPing to the SA host... as below this works.
However from the Driver in my javascript / node environment... still get this:
Code: -2004 Msg: Can't initialize DBCAPI

Perhaps environment variables need to be set separately in the node environment...?
What is the NODE_PATH supposed to contain? Path to the current active version of Node?


$ dbping -c "Host=;Server=mySvr" -z
SQL Anywhere Server Ping Utility Version 17.0.10.6178
Application information:
HOST=####.local;OSUSER=###;OS='Darwin 19.6.0 x86_64';EXE=/Applications/SQLAnywhere17/System/bin64/dbping;PID=0x33c5;THREAD=0x11d342dc0;VERSION=17.0.10.6178;API=DBLIB;TIMEZONEADJUSTMENT=-360
Attempting to connect using:
ServerName=mySvr;Host=
Attempting to connect to a running server...
Trying to start TCPIP link ...
My IP address is 127.0.0.1
My IP address is ::1%1
My IP address is fe80::1%1
My IP address is ###
My IP address is ###
My IP address is ###
My IP address is ###
My IP address is ###
My IP address is ###
My IP address is ###
TCPIP link started successfully
Attempting TCPIP connection (address :2638 found in sasrv.ini cache)
Looking for server with name mysvr
Trying to find server at cached address :2638 without broadcasting
Found database server mySvr on TCPIP link
Connected using client address ipaddress:localport
Connected to server over TCPIP
Connected to SQL Anywhere Server version 17.0.4.2053
Client disconnected
Disconnected from server
Ping server successful.
$

@redevill
Copy link
Author

redevill commented Mar 28, 2022

This is the code being used with the driver in the node environment. (Node 12.22.1)
sqlanywhere driver V1.0.27

var sqlanywhere = require('sqlanywhere');
const conn_params = { Host: 'xxx.xxx.xxx.xxx', Server: 'mySvr', UserId: 'dba', Password: 'sql' };
const conn = sqlanywhere.createConnection();
conn.connect(conn_params, (err: Error) => {
if (err) throw err; console.log('connected ' + conn.connected()); conn.exec('SELECT name FROM orion', [301], (err: Error, result: any) => {
if (err) throw err;

console.log(result); conn.disconnect(); }); });

// The environment variable is set.
image

the content of the sa_config.sh was added to my bash_profile.

@DanCummins-SAP
Copy link
Contributor

Hello again,

Is the file there?
I had to run the setup from the install image, which installs a lib64 with a dbcapi inside (not the same as the lib64 in the install image). I thought I should mention that since it's confusing how to run the installer on Mac. The GUI installer might not run on modern macOS (working on getting it Notarized). As a workaround you can use the character mode installer.

To use the character-mode installer, run the "setup" script from the Install SQL Anywhere app by launching:
Contents/Resources/sqlany17/setup

Maybe the file is there, but won't load for another reason? Can you try:
otool -L libdbcapi_r.dylib

The output should look something like this:

libdbcapi_r.dylib:
@rpath/libdbcapi_r.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libdblib17_r.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libdbtasks17_r.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)

Hopefully those can be found in the DYLD_LIBRARY_PATH (hopefully that variable is not getting disabled somehow in your environment).

If that does not lead to a solution, can you gather the output from "dtruss"?

Dan

@DanCummins-SAP
Copy link
Contributor

For NODE_PATH, it should contain the path to the node_modules directory of your Node distribution.
Like other tools, there is a global and a per-user setting. You can see these with:
npm root
npm -g root

So for example if you "npm -g install node-sqlanywhere" it will go in the global place.

Dan

@redevill
Copy link
Author

redevill commented Mar 30, 2022

So I did check to see if the file "libdbcapi_r.dylib actually existed in the folder - It was there.
After putting all the config into my bash profile, I double checked that the $ENVVARS had values that made sense.

With the exception of NODE_PATH... this I was a bit uncertain as I use a version manager called n... It swaps out node installs based on need. I tracked down its location, and then set the NODE_PATH to

export SQLANY17=/Applications/SQLAnywhere17/System
NODE_PATH="/Users/Eti/n/bin/node" NODE_PATH="$SQLANY17/node:${NODE_PATH:-}" export NODE_PATH

I will look into dtruss

@TorbenI
Copy link

TorbenI commented Feb 3, 2023

Hi @redevill . Did you find a solution for your problem? I get the same error on connecting to the database.
The SQLANY_API_DLL path is set to the libdbcapi_r.dylib (the file exists and otool is showing the result from @DanCummins-SAP). Also SQLANY17=/Applications/SQLAnywhere17/System is set.
I installed the sql-anywhere app with the setup file (Contents/Resources/sqlany17/setup)

@redevill
Copy link
Author

redevill commented Feb 3, 2023

@TorbenI - Sorry, we did not find a solution, and no more budget for the effort.

@TorbenI
Copy link

TorbenI commented Feb 4, 2023

@redevill Thanks for your response :). Sad to hear that it didn‘t work. Maybe I will find someone who managed to get it working on MacOS.

@DenisBessa
Copy link

If you came here looking for answers, here is a functioning config for a node.js app with all dependencies running on Docker:

(this took me several hours)

# Wont work with any version newer version of node
FROM --platform=linux/amd64 node:12

# Build dependencies
RUN apt-get install -y make gcc g++ python3

# Avoid "gyp ERR! stack Error: certificate has expired"
ENV NODE_TLS_REJECT_UNAUTHORIZED=0

WORKDIR /app

ENV SQLANY17="/opt/sqlanywhere17" \
    LD_LIBRARY_PATH="/opt/sqlanywhere17/lib64:${LD_LIBRARY_PATH}" \
    NODE_PATH="/opt/sqlanywhere17/node:${NODE_PATH}" \
    PATH="/opt/sqlanywhere17/bin64:/opt/sqlanywhere17/bin32:${PATH}"

# Install SQL Anywhere client
RUN wget http://d5d4ifzqzkhwt.cloudfront.net/sqla17developer/bin/sqla17developerlinux.tar.gz -P /opt/sqlanywhere17/installation \
    && tar zxvf /opt/sqlanywhere17/installation/sqla17developerlinux.tar.gz -C /opt/sqlanywhere17/installation

RUN sh /opt/sqlanywhere17/installation/sqlany17/setup -silent -I_accept_the_license_agreement -type CREATE
RUN rm -rf /opt/sqlanywhere17/installation

COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build

# # Needs to install SQL Anywhere again to get the right binaries
RUN npm i sqlanywhere

EXPOSE 3000

CMD ["node", "/app/dist/index.js"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants