使用 node.js oracledb 连接到 Oracle DB

Connect to Oracle DB using node.js oracledb

我正在尝试使用 Node.js 的官方 node-oracledb 驱动程序连接到 Oracle 数据库并接收:

ORA-12154: TNS: could not resolve the connect identifier specified. var oracledb = require('oracledb'); oracledb.getConnection({ user: "", password: "", connectString: "DNS=MY;UID=MYNAME;PWD=MYPWD" }, function(err, connection) {...

Excel (connectString="ODBC;DNS=MY;UID=MYNAME;PWD=MYPWD") 中的相同 connectString 工作正常,以及 tnsping 到数据库,所以它与 TNS 配置和环境变量无关。

请注意the documentation on connectString。您可以使用轻松连接语法或网络服务名称语法。 ODBC 未记录为受支持的语法。

如果您查看 Windows 中的 ODBC 配置(如果需要,Google),您应该能够识别数据库的服务器和端口(默认端口为 1521)以及您正在使用的服务名称。获得这些值后,您应该能够使用简单的连接语法相当轻松地创建 connectString。

另外,用户和密码值应该通过它们指定的参数,而不是通过 connectString 参数。