Problem in brief:
My Oracle db is running on a remote host and a non-standard port. I can connect
to the db as scott via ruby installed on my win2k PC but I cannot figure out how
to get a connection via rails (installed on the same PC).
I suspect my settings in database.yml are wrong, but I''ve tried all the
variations I can think of without success.
I''d really like to get the connection working via rails.
[I also don''t know why my ruby call (that works) doesn''t need
the port number, although I do have a local tns_names.ora.]
Details
I''ve worked through Rolling with Ruby on Rails against a MySQL database
successfully after installing the following gems:
$ ls *.gem
actionmailer-0.8.1.gem activerecord-1.9.1.gem rake-0.5.0.gem
actionpack-1.7.0.gem activesupport-1.0.3.gem
actionwebservice-0.6.2.gem rails-0.11.1.gem
I''m running ruby 1.8.2 (2004-12-25) [i386-mswin32]
I now want to connect to a remote Oracle database via Rails.
I installed ruby-oci8-0.1.9-mswin.rb.
I''ve set up a rails application (emp) and edited its database.yml:
development:
adapter: oci
database: <my db sid here>
host: <my db host ip here>
username: scott
password: tiger
[Note: the oci adapter appears to actually call the oci8.rb]
I''ve restarted the server.
Along the way, I can connect to my oracle db via ruby:
$ ruby -r oci8 -e ''OCI8.new("scott", "tiger",
"<my sid here>").exec("select * from emp") do |r| puts
r.join(","); end''
7369,SMITH,CLERK,7902,1980/12/17 00:00:00,800.0,,20
7499,ALLEN,SALESMAN,7698,1981/02/20 00:00:00,1600.0,300.0,30
...
Beautiful!
I''ve set up my model and controller in rails.
But I get this from the server:
OCIError in Emp#new
ORA-12541: TNS:no listener
script/server:48
Show framework trace
d:/ruby/lib/ruby/site_ruby/1.8/oci8.rb:99:in `attach''
d:/ruby/lib/ruby/site_ruby/1.8/oci8.rb:99:in `initialize''
d:/ruby/lib/ruby/site_ruby/1.8/oci8.rb:99:in `do_ocicall''
d:/ruby/lib/ruby/site_ruby/1.8/oci8.rb:99:in `initialize''
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/connection_adapters/oci_adapter.rb:211:in
`new''
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/connection_adapters/oci_adapter.rb:211:in
`oci_connection''
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/connection_adapters/abstract_adapter.rb:136:in
`send''
...
The call in oci_adapter.rb (line 211) looks similar to the ruby call (that
works):
module ActiveRecord
class Base
def self.oci_connection(config) #:nodoc:
conn = OCI8.new config[:username], config[:password], config[:host]
There is a TNS listener running on the db host listener on the configured port -
I''m using that listener now for other apps. Also the call from Ruby
(that works) would be using the same listener. So, rails is either not reaching
the correct host or is not using the correct port. It cannot know the correct
port unless it looks up the tns_names.ora, but then ruby managed ok without
being told the port.
Any help, much appreciated.
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm