我有一臺運行Oracle的服務器,IP爲192.168.1.50。無法將我的Rails應用程序連接到Oracle
在我的Linux機器上,我需要連接到這個Oracle服務器。然後我安裝了Oracle即時客戶端,並相應地設置環境變量:
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
我也安裝了相應的寶石:
ruby-oci8 (2.1.0)
一旦我確定我的模型,跑耙分貝:遷移,我得到了以下錯誤消息:
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/[email protected]: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>
在這個配置文件中是否缺少某些東西?
UPDATE
我已經從命令行測試,並在連接工作正常:
紅寶石-rubygems -e「需要 '的oci8'; OCI8.new( '用戶', 'PASS' , '192.168.1.50/ORCL')執行(「SELECT * FROM用戶)做的| r |提出r.join( '');結束」
=> OK
同樣從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
我都定義;刪除主機解決了這個問題。 – tamersalama 2016-01-13 20:42:49