Your config/database.yml will look something like:
development: adapter:oci database: orcl host: username: username password: password
At least in AR 1.10.1, the OCI adapter doesn’t use database, it uses host, so that should be:
development: adapter: oci database: host: orcl username: username password: password
If you don’t have a tnsnames.ora configured for your environment, and you are using the 10g instantclient install, you can specify a connect string for the host parameter. Example:
development: adapter: oci host: //server.example.com:port/instance_name username: username password: password
Note: Make sure you Install Active Record. gem install activerecord
Note: Please make sure that the ruby/OCI8 driver(http://rubyforge.org/projects/ruby-oci8/) is installed or else an AdapterNotFound exception will be thrown when starting the web server
THIS IS THE PLACE TO GO FOR MAC >
http://creativi.st/blog/articles/2005/06/25/rails-oracle-client-on-mac-os-xNewer instructions for Intel Macs Better new instructions for Intel Macs (using the new Intel Mac Oracle InstantClient)
just remember to do this also, so your “ruby.h” (ruby header file) is found for the ‘make’ command.
cd /usr/lib/ruby/1.8/powerpc-darwin8.0
sudo ln -s ../universal-darwin8.0/* ./
found here:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/76928193a89bd420/5b7d897c4316a6d0
- Grant Aaron
Another Note: I had to try several configurations before this worked for me. My Configuration:
- Rails 1.0.0
- activerecord (1.13.2)
- Oracle 90 client with configured TNSNAMES.ora
- Default MSQL DB in 'database.yml'
- ruby/OCI8 driver for windows
- Oracle Database connection defined in my object model:
class Stream < ActiveRecord::Base
establish_connection({
:adapter => "oci",
:host => "SID.COMPANY.NET",
:username => "user",
:password => "pass"
})
set_table_name "mytable"
end
My specific issue was that the entry name in TNSNAMES.ora is not the same as the service name of that entry. The host must contain the entry name (which happens to be ‘SID.COMPANY.NET’) in TNSnames and not the service name (ex: ‘sid’).
To use Oracle with FastCGI, see HowToUseOracleWithFastCGI
Your issue had nothing to do with using establish_connection over database.yml. My bet would be that if you pulled your establish connection back out into database.yml it will work fine now. Rails uses database.yml to load a variable called RAILS_ENV which is (by default) read from in establish_connection. All you did (too much work) was overwrite establish_connection to do this manually.
(Full article here)
If you want to use the ‘new’ oracle adapter rather than oci and you want to use host/SID style of database server reference you have to use ‘database’ rather than ‘host’, see [PATCH] Rename oracle_adapter, keep up w/ the Joneses for more details. – AndrewBeacock
database.yml
development: adapter: oracle database: [your database as it appears on TNSNAMES.ora] username: [your username] password: [your password]The oracle adapter does not exist on Rails 2 by default so: