我正在编写一个 Node.js 应用程序,用于从 Oracle 数据库中提取数据。 DBA 最近将数据库迁移到另一台机器上,一切都崩溃了。
我尝试重新创建 tnsnames.ora 和 sqlnet.ora 文件。我相当确定它们是正确的,因为 sqlplus 可以很好地连接到该服务。但node-oracle一直报错:“ORA-12154: TNS:无法解析指定的连接标识符”。
这对我来说是无法解释的。在我看来,如果我设置了 ORACLE_HOME 环境变量,那么 node-oracle 和 sqlplus 的功能应该相同。我做错了什么?
我尝试切换到node-db-oracle,但它报告了同样的问题。我被难住了。
编辑:这就是我的连接方式:
database = new oracle.Database({
hostname: Preferences["oracle_host"], // FQDN of the database
port: Preferences["oracle_port"],
user: Credentials["oracle_login"],
password: Credentials["oracle_password"],
database: Preferences["oracle_database"]
});
connection = database.connect(function(error) {
if(error) {
Utilities.logger.error(error);
}
else {
Utilities.logger.info("Connected to Oracle database " + Preferences["oracle_host"]);
if(callback) callback.call(this, collection, options);
connection = this;
}
});
最佳答案
我可以使用 sqlplus 连接,但不能使用 Nodejs。我是这样连接的
oracledb.getConnection(
{
user : "test",
password : "test",
connectString : "150.150.50.50:1521/MYDB"
}
对我有用的解决方案是编辑 sqlnet.ora 文件并更改
names.directory_path = (TNSNAMES)
至
names.directory_path = (TNSNAMES, EZCONNECT)
关于Node.js 和 node-oracle : Problems connecting to Oracle database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11568428/