ruby-on-rails – 无法将我的rails应用程序连接到Oracle

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 无法将我的rails应用程序连接到Oracle前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一台运行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 = /家庭/ 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中有什么东西丢失吗?

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")

=>好

但仍然无法使用我的rails应用程序.

更新2

数据库而不是主机修复了这个东西:

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

解决方法

数据库而不是主机修复了这个东西:
development:
  adapter: oracle_enhanced
  database:  //192.168.1.50:1521/orcl
  username: USER
  password: PASS
@H_502_50@ @H_502_50@

猜你在找的Ruby相关文章