Search code examples
ruby-on-rails-3oracle-databasedatamappertnsnames

Using tnsnames.ora in database.yml


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.


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 }