gpt4 book ai didi

ruby-on-rails - 无法将Rails应用程序连接到Oracle

转载 作者:行者123 更新时间:2023-12-04 03:39:48 25 4
gpt4 key购买 nike

我有一台运行Oracle的服务器,IP为192.168.1.50。

在我的Linux机器上,我需要连接到该Oracle服务器。然后,我安装了Oracle Instant Client并相应地设置了环境变量:

OCI_INCLUDE_DIR =/home/luc/instantclient_11_2/sdk/include
LD_LIBRARY_PATH =/home/luc/instantclient_11_2
DYLD_LIBRARY_PATH =/home/luc/instantclient_11_2/
OCI_LIB_DIR =/home/luc/instantclient_11_2
ORACLE_HOME =/home/luc/instantclient_11_2

我还安装了适当的gem:

ruby-oci8 (2.1.0)

一旦定义了模型并运行rake db:migrate,我将收到以下错误消息:
rake aborted!
ORA-12154: TNS:could not resolve the connect identifier specified
oci8.c:360:in oci8lib_191.so
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/ruby-oci8-2.1.0/lib/oci8/oci8.rb:123:in `initialize'
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:319:in `new'
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:319:in `new_connection'
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:429:in `initialize'
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in `new'
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in `initialize'
/home/luc/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in `new'
....

我的database.yml是:
development:
adapter: oracle_enhanced
host: 192.168.1.50:1521/orcl
username: USER
password: PASS

sqlplus连接可以完美地工作:
sqlplus USER/PASS@192.168.1.50:1521/orcl

SQL*Plus: Release 11.2.0.3.0 Production on Wed Mar 21 17:34:26 2012

Copyright (c) 1982, 2011, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

这个 session 上有什么遗漏吗?

更新

我已经从命令行进行了测试,并且连接工作正常:

ruby -rubygems -e“要求'oci8'; OCI8.new('USER','PASS','192.168.1.50/orcl').exec('select * from users')do | r |将r.join( ','); 结尾”

=>好

irb也是如此:
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "//192.168.1.50/orcl",:username => "USER",:password => "PASS")

=>好

但仍然无法通过我的Rails应用程序运行。

更新2

使用数据库而不是主机来解决问题:
development:
adapter: oracle_enhanced
database: //192.168.1.50:1521/orcl
username: USER
password: PASS

最佳答案

使用数据库而不是主机来解决问题:

development:
adapter: oracle_enhanced
database: //192.168.1.50:1521/orcl
username: USER
password: PASS

关于ruby-on-rails - 无法将Rails应用程序连接到Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com