6 Replies Latest reply: Dec 15, 2009 11:23 AM by dvohra21 RSS

    Test Oracle connectivity with Ruby on Rails

    561284
      Hi all,

      I've installed Ruby 1.8.6 and Rails 2.2.2 in Windows. I'm using Oracle Instant Client and added it to PATH env variable and used below commands to install ruby-oci8 library.

      ruby ruby-oci8-1.0.3-mswin32.rb
      gem install ruby-oci8 –v 1.0.3

      TNSNAMES.ora is setup correctly, as I could connect the database using sql plus. But the below command throws "ruby.exe - Entry Point Not Found" error which shows the message "*The procedure entry point OCILobGetChunkSize could not be located in the dynamic library oci.dll*"

      C:\ruby\learning>ruby -r oci8 -e "OCI8.new('apps', 'pwd', 'dvl01').exec('SELECT 1 from dual') {|r| puts r.join}"

      c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/oci8lib.so: 127: The specified procedure could not be found. - c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/oci8lib.so (LoadError)
      from c:/ruby/lib/ruby/site_ruby/1.8/oci8.rb:20

      Please help me resolve this issue.

      Thanks
      Kishore
        • 1. Re: Test Oracle connectivity with Ruby on Rails
          561284
          I could get it working, by adding Oracle Instant client directory to the front of the PATH variable. Then I ended up with *"ORA-12154: TNS:could not resolve the connect identifier specified"*. I've setup TNSNAMES.ora correctly in three ORACLE_HOMEs I've for Forms, Workflows and Discoverer 10g.

          The following command did work though, when host name, port and sid are used

          *ruby -r oci8 -e "OCI8.new('apps', 'dcs1', '//host:1554/dvl01').exec('SELECT 1 from dual') {|r| puts  r.join}"*

          How does oci8 refer to TNSNAMES.ora?
          • 2. Re: Test Oracle connectivity with Ruby on Rails
            586655
            Ruby-OCI8 doesn't depend on TNSNAMES.ora if you use the [EASY CONNECT NAMING|http://www.oracle.com/technology/products/oraclenet/files/OracleNetServices_NetEasyConnect.pdf] (a.k.a '//host:1554/dvl01'). The correct form is +host\[:port\]/service_name+ , and <host> is required, and should be a valid DNS host name or IP, <service_name> is the service name of the database instance. Please check these two are set correctly. Sometime the <service_name> may look like 'dvl01.dnsdomain.com'.

            Edited by: Jesse.Hu on Feb 1, 2009 3:03 PM

            Edited by: Jesse.Hu on Feb 1, 2009 3:04 PM
            • 3. Re: Test Oracle connectivity with Ruby on Rails
              700163
              Which values exactly should I put in my database.yml file? I'm trying to coonect to Oracle XE installed on my PC on Windows XP, Ruby 1.8.6, Rails 2.3.2 with Oracle adapter?
              I tried as follows:
              development:
                adapter: oracle
                encoding: utf8
                database: localhost:1521/incentives_development,
                
                username: SYSTEM
                password: admin
              and I got the same error as others:
              rake aborted!
              ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
              rake aborted!
              Invalid escape character syntax: /C:\Documents and Settings\myusername\My Documents\rails projects\incentives\Rakefile/
              c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2058:in `standard_exception_handling': Invalid escape character syntax: /C:\Documents and Settings\myusername\My Documents\rails projects\incentives\Rakefile/ (RegexpError)
                      from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2058:in `find'
                      from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2058:in `each'
                      from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2058:in `find'
                      from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2058:in `standard_exception_handling'
                      from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in `run'
                      from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31
                      from C:/ruby/bin/rake:19:in `load'
                      from C:/ruby/bin/rake:19
              Edited by: user11136587 on 7 mai 2009 02:02

              Edited by: user11136587 on 7 mai 2009 02:03
              • 4. Re: Test Oracle connectivity with Ruby on Rails
                cj
                For Oracle XE running on the same machine as Rails, try the connection string:

                localhost/XE

                The port defaults to 1521 so there is no need to include that
                • 5. Re: Test Oracle connectivity with Ruby on Rails
                  688388
                  Hi Kishore,
                  While you run the below line in CMD line your would be getting the following prompt

                  C:\Documents and Settings\Administrator>ruby H:\RUBY\ruby-oci8-1.0.3-mswin32.rb
                  Copy OCI8.rb to c:/ruby/lib/ruby/site_ruby/1.8/dbd
                  Copy oci8.rb to c:/ruby/lib/ruby/site_ruby/1.8
                  Copy oci8lib.so to c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt
                  OK?

                  Enter Yes/No: Yes
                  Copying OCI8.rb to c:/ruby/lib/ruby/site_ruby/1.8/dbd ... done
                  Copying oci8.rb to c:/ruby/lib/ruby/site_ruby/1.8 ... done
                  Copying oci8lib.so to c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt ..
                  OK


                  The appropriate libraries would be copied automatically

                  ---------------
                  Kindly mark the post if it helps
                  • 6. Re: Test Oracle connectivity with Ruby on Rails
                    dvohra21
                    http://www.oracle.com/technology/pub/articles/fernandez-rails-connections.html
                    http://www.oracle.com/technology/pub/articles/saternos-ror-faq.html
                    http://wiki.oracle.com/page/Using+Oracle+and+Ruby+on+Rails

                    Edited by: dvohra16 on Dec 15, 2009 9:23 AM