我有一台运行Oracle的服务器,IP是192.168.1.50。
在我的linux机器上,我需要连接到这个Oracle服务器。然后我安装了Oracle Instant Client并相应地设置了环境变量:
OCI_INCLUDE_DIR = /家庭/ LUC / instantclient_11_2 / SDK /包括
LD_LIBRARY_PATH = /家庭/ LUC / instantclient_11_2
DYLD_LIBRARY_PATH = /家庭/ LUC / instantclient_11_2 /
OCI_LIB_DIR = /家庭/ 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>
此conf中是否缺少某些内容?
更新
我已从命令行进行测试,连接正常:
ruby -rubygems -e“require'oci8'; OCI8.new('USER','PASS','192.168.1.50 / orcl').exec('select * from users')do | r | puts 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
答案 0 :(得分:10)
使用数据库代替主机修复了这个问题:
development:
adapter: oracle_enhanced
database: //192.168.1.50:1521/orcl
username: USER
password: PASS
答案 1 :(得分:2)
如果要使用EZConnect语法连接到Oracle,host
文件中的database.yml
将需要包含前导斜杠,即
host: //192.168.1.50:1521/orcl
在Connecting to Oracle in Ruby on Rails上的这篇OTN文章中,有一些其他方法可以配置Rails来访问Oracle数据库。