Oracle DB 与 Node 的连接.js获取"Error: Schema User name is not Set! Try Set Environment Variable NODE_ORAC



我已经安装了Node JS版本12,从github克隆了node-oracle db。

我还设置了本文中提到的OCI_LIB_DIR路径。

module.exports = {
user          : process.env.NODE_ORACLEDB_USER || "hr",
// Get the password from the environment variable
// NODE_ORACLEDB_PASSWORD.  The password could also be a hard coded
// string (not recommended), or it could be prompted for.
// Alternatively use External Authentication so that no password is
// needed.
password      : process.env.NODE_ORACLEDB_PASSWORD || abcd,
// For information on connection strings see:
// https://oracle.github.io/node-oracledb/doc/api.html#connectionstrings
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "jdbc:oracle:thin:@localhost:1521/orcl",
// Setting externalAuth is optional.  It defaults to false.  See:
// https://oracle.github.io/node-oracledb/doc/api.html#extauth
externalAuth  : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};

我已经在SQL开发人员中创建了一个基本连接,它会有所帮助吗?

我已经在node-oracledb中安装了npm并设置了用户名,但是当我尝试运行命令"npm test"时,它给了我错误

Deeksha ~/Desktop/nodewithoracle/node-oracledb (master)
$ npm test
> oracledb@4.1.0 test C:UsersDeekshaDesktopnodewithoraclenode-oracledb
> mocha --opts test/opts/mocha.opts
C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesyargsyargs.js:1163
else throw err
^
Error: Schema User name is not Set! Try Set Environment Variable NODE_ORACLEDB_USER.
at Object.<anonymous> (C:UsersDeekshaDesktopnodewithoraclenode-oracledbtestdbconfig.js:48:9)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:Users850044533Desktopnodewithoraclenode-oracledbtestnotes.js:32:18)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibmocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibmocha.js:327:14)
at Mocha.run (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibmocha.js:804:10)
at Object.exports.singleRun (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibclirun-helpers.js:207:16)
at exports.runMocha (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibclirun-helpers.js:300:13)
at Object.exports.handler (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibclirun.js:296:3)
at Object.runCommand (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesyargslibcommand.js:242:26)
at Object.parseArgs [as _parseArgs] (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesyargsyargs.js:1087:28)
at Object.parse (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesyargsyargs.js:566:25)
at Object.exports.main (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochalibclicli.js:63:6)
at Object.<anonymous> (C:UsersDeekshaDesktopnodewithoraclenode-oracledbnode_modulesmochabin_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
npm ERR! Test failed.  See above for more details.
  • 在启动 Node.js 之前将凭证环境变量设置为数据库凭证值。 错误消息指出未设置NODE_ORACLEDB_USER

    或者,您可以直接在getConnection()调用中设置值:

    connection = await oracledb.getConnection({ user: 'hr', password: 'welcome', connectString: 'localhost/orcl' });

    但要小心硬编码密码。

  • 使用有效的连接字符串;JDBC 连接字符串不可用(Node.js 不是 JDBC(。 请参阅 node-oracledb 文档 JDBC 和 Oracle SQL Developer Connection String,了解如何确定要使用的内容。 根据您发布的内容,您应该只使用localhost:1521/orcl.

节省一些时间,并阅读 node-oracledb 安装手册、文档和示例。

最新更新