首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Oracle连接与Node.js获取“错误:模式用户名未设置!请尝试设置环境变量NODE_ORACLEDB_USER”。

Oracle连接与Node.js获取“错误:模式用户名未设置!请尝试设置环境变量NODE_ORACLEDB_USER”。
EN

Stack Overflow用户
提问于 2020-01-01 11:03:43
回答 1查看 1.3K关注 0票数 0

我已经安装了Node版本12,从github克隆节点-oracle。

我还设置了OCI_LIB_DIR路径,如本文章中所提到的。

代码语言:javascript
复制
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中创建了一个基本的连接,它会有帮助吗?

我已经在节点oracledb中安装了npm,并且设置了用户名,但是当我尝试运行命令"npm test“时,它会给出错误。

代码语言:javascript
复制
Deeksha ~/Desktop/nodewithoracle/node-oracledb (master)
$ npm test

> oracledb@4.1.0 test C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb
> mocha --opts test/opts/mocha.opts

C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:1163
      else throw err
           ^

Error: Schema User name is not Set! Try Set Environment Variable NODE_ORACLEDB_USER.
    at Object.<anonymous> (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\test\dbconfig.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:\Users\850044533\Desktop\nodewithoracle\node-oracledb\test\notes.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:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:330:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:327:14)
    at Mocha.run (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:804:10)
    at Object.exports.singleRun (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run-helpers.js:207:16)
    at exports.runMocha (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run-helpers.js:300:13)
    at Object.exports.handler (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run.js:296:3)
    at Object.runCommand (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\lib\command.js:242:26)
    at Object.parseArgs [as _parseArgs] (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:1087:28)
    at Object.parse (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:566:25)
    at Object.exports.main (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\cli.js:63:6)
    at Object.<anonymous> (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\bin\_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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-01 22:41:08

  • 在启动Node.js之前,将凭据环境变量设置为DB凭据值。错误消息说NODE_ORACLEDB_USER不是set.Alternatively,您可以在getConnection()调用中直接设置值: connection = await oracledb.getConnection({ user: 'hr', password: 'welcome', connectString: 'localhost/orcl' }); 但是要小心密码的硬编码。
  • 使用有效的连接字符串;JDBC连接字符串不可用(Node.js不是JDBC)。有关如何确定使用什么,请参见节点oracledb JDBC和Oracle SQL Developer连接字符串。根据您发布的内容,您应该只使用localhost:1521/orcl

节省一些时间,阅读节点-oracledb 安装手册文档示例

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59551931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档