12

My goal is to connect to a oracle database on a VMWare guest machine (OpenSuse) from Ubuntu.

For now I have only installed the oracledb driver, and was trying to run the example connect program given.

The steps that I am following are from the github INSTALL page. What I have done till now are these :

1) Since I have node.js already installed I skipped the step 3.1.

2) I have successfully downloaded and extracted the basic and sdk as mentioned in step 3.2.

3) Since I couldn't find any package named libaio but I did found libaio1. So I installed libaio1.

4) I made the environment variable LD_LIBRARY_PATH and the contents of it on my PC is /opt/oracle/instantclient.

5) As mentioned in step 3.3; even though it wasn't mandatory in my case; I made two environment variables: OCI_LIB_DIR with contents /opt/oracle/instantclient and OCI_INC_DIR with contents /opt/oracle/instantclient/sdk/include.

6) Installed node-oracledb.

I am trying to run the example connect program. The code that I am using is here https://github.com/ishanatmuz/oracle-test. When I run node connect.js I am getting this error.

/home/ishan/node.js/oracle-test/node_modules/oracledb/lib/oracledb.js:28
throw err;
          ^
Error: libclntsh.so.12.1: cannot open shared object file: No such file or directory
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/ishan/node.js/oracle-test/node_modules/oracledb/lib/oracledb.js:23:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (modullibclntsh.so.12.1e.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Since I haven't started the VMware guest machine yet; I was hoping of getting an error regarding no such database instance found. And then only after that run the VMWare machine and connect to the database inside it. But instead I am getting the error of cannot open shared object file for libclntsh.so.12.1.

4

2 回答 2

20

我的第一个怀疑是 LD_LIBRARY_PATH 实际上没有正确设置或导出。三重检查它是否已设置,并且尝试启动节点的实际 shell 可以读取该目录。

export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2

您需要在任何启动 Node.js 的 shell 中执行此操作。

我还会检查机器上安装了哪些其他 Oracle 库,并确保没有冲突。

使用 ldconfig 全局设置路径几乎肯定比设置 LD_LIBRARY_PATH 更容易。您可以执行以下操作:

sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig

有关详细信息,请参阅Instant Client 安装说明。

如果您有可选的网络配置文件,例如sqlnet.oraor tnsnames.ora,它们可以放在一个目录中,该目录/opt/oracle/instantclient_12_2/network/admin是配置文件的默认位置。请参阅可选的 Oracle 网络配置

更新:如果您安装 Instant Client 19.3 RPM 软件包,该ldconfig步骤将自动完成。(对于 19.3 ZIP 文件安装,您仍然需要/可以/应该这样做)

Instant Client 19 将连接到 Oracle Database 11.2 或更高版本,因此请使用 Instant Client 19,除非您对旧版本有特殊要求。

于 2015-04-17T00:57:15.117 回答
6

导出仅适用于一个进程。看来,它不会出现在您的终端窗口中(它是单独的过程)。因此,您应该在开始之前再次执行以下node connect.js操作(在您要启动节点的同一终端窗口中):

export LD_LIBRARY_PATH=/opt/oracle/instantclient:$LD_LIBRARY_PATH
于 2016-06-29T10:23:08.473 回答