Luc*_*Luc 9 oracle ruby-on-rails ruby-on-rails-3
我有一台运行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)
Run Code Online (Sandbox Code Playgroud)
一旦我定义了模型并运行了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'
....
Run Code Online (Sandbox Code Playgroud)
我的database.yml是:
development:
adapter: oracle_enhanced
host: 192.168.1.50:1521/orcl
username: USER
password: PASS
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
这个conf中有什么东西丢失吗?
UPDATE
我已从命令行测试,连接正常:
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")
Run Code Online (Sandbox Code Playgroud)
=>好的
但仍然无法使用我的rails应用程序.
更新2
使用数据库代替主机修复了这个问题:
development:
adapter: oracle_enhanced
database: //192.168.1.50:1521/orcl
username: USER
password: PASS
Run Code Online (Sandbox Code Playgroud)
Luc*_*Luc 10
使用数据库代替主机修复了这个问题:
development:
adapter: oracle_enhanced
database: //192.168.1.50:1521/orcl
username: USER
password: PASS
Run Code Online (Sandbox Code Playgroud)