Question

How can I use the database connection information in tnsnames.ora when connecting with Rails?

I tried setting the database: or the host: fields in the database.yml to the SID, but neither worked.

I verified that sqlplus can connect to the database, so the tnsnames.ora is correct.

I'm using DataMapper on Rails 3 if that helps at all.

Was it helpful?

Solution

I think we spoke in #datamapper a couple days ago. Sqlplus is a piece of Oracle software which interfaces with what i presume is their loadbalancing system.

DataMapper assumes that there is a 1 to 1 mapping between a repository and a datastore. Typically this means that you assume that load balancing is handled datastore side (say mysql or postgres clustering).

However, there is nothing preventing someone from writing a library that would let DataMapper hot swap between a group of repositories, if it were possible to get a readout of the load on each of the datastores associated with each repository (i.e. write your own little load balancing router).

The company i work for uses DataMapper repositories in exactly this fashion (for separability of records, rather than for load balancing).

it's as simple as:

DataMapper.repository(seed_repository_symbol) { return your_code_block.call }

OTHER TIPS

After a few hours of fussing with this myself I discovered the answer to be:

# WORKS
development:
  adapter: oracle
  host: devdb
  username: user
  password: pwd

I'm using Rails 3.2.1, DM 1.2.0 on Win7 with both 32-bit and 64-bit regular Oracle clients installed.

One very important thing I discovered along the way: You must restart the rails dev server between each mod of database.yml to pick up the changes. I wasted a lot of time not knowing this. For some reason the DataMapper setup wasn't picking up changes here like is normal with the dev server.

History:

I was told the answer was this (by another developer at another company who uses JRuby on Windows):

# DID NOT WORK
development:
  adapter: oracle
  database: user/pwd@devdb

That did not work for me and I suspected the answer was to use a colon (based on DataMapper.setup syntax):

# DID NOT WORK
development:
  adapter: oracle
  database: user:pwd@devdb

This did not work either so I tested manual connections in the IRM and studied the response from DataMapper.setup. It puts the SID in host and does not indicate database so I tried the same in database.yml. It worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top