我使用activerecord-oracle_enhanced-adapter连接到Oracle 11g数据库,以便我可以更轻松地在我的Rails 4应用程序中引用Oracle中的数据。到目前为止,我一直在遵循GitHub仓库中的说明,看起来好像我实际上能够连接到我想要的数据库,但每当我去查询Oracle数据库中的任何数据时,我都会收到以下错误:
NoMethodError: undefined method `match' for nil:NilClass
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:322:in `new_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:389:in `initialize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:26:in `new'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:26:in `initialize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/connection.rb:9:in `new'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/connection.rb:9:in `create'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:156:in `oracle_enhanced_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
from /Users/47900/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
from /Users/47900/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
我曾尝试使用Google搜索问题(以及查看文档/问题),但未发现任何有用的信息。我也可以通过sqlplus访问这个数据库,所以我的Oracle Instant Client实际上正在工作。这是我已经配置并用于尝试查询Oracle DB的database.yml和model:
#database.yml (obviously data is faked)
development:
adapter: oracle_enhanced
host: //127.0.0.1:1527/DATABASE_NAME
username: ENV['USERNAME']
password: ENV['PASSWORD']
#oracle.rb
class Oracle < ActiveRecord::Base
self.table_name = "SCHEMA.TABLE"
self.primary_key = "obj_id"
end
#The queries I have tried through Rails Console
>> Oracle
>> ActiveRecord::Base.connection.execute("SELECT * FROM TABLE WHERE obj_id > 1000000;")
我会在获取更多信息时不断更新,非常感谢您提前!
答案 0 :(得分:1)
在database.yml配置文件中,您缺少&#34;数据库&#34;。使用https://github.com/rsim/oracle-enhanced#database-connection
中描述的database.yml文件检查此代码https://github.com/rsim/oracle-enhanced/blob/master/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb行:302和322
的database.yml
development:
adapter: oracle_enhanced
host: 127.0.0.1
port: 1527
database: <DATABASE_NAME>
username: ENV['USERNAME']
password: ENV['PASSWORD']