Rails App Database in MySQL - OK, However what if I need to access multiple Databases of different types ie. Sybase, MSSQL and Oracle

Problem:

I have an intranet-based application in a company network - using rails. The application has many sub-applications which may be composed of a handful of pages each.

The web application has its own database using MySQL which contains all application specific data, however, I need to retrieve data from different sources which maybe, MSSQL, Oracle or Sybase databases.

For example, I need to access a well establish Sybase database server which contains trade data so I can create a summary of daily Profit & Loss - after filtering, various calculations I will archive this summary data in the Applications MySQL DB for performance views etc.over time.

The Question:

In rails how do I do this neatly, rails is designed to use one database right? Would anyone be able to suggest ways in which I can access such data?

Set up the database connection in database.yml. Let's say it's named "sybasefu".

In the models that need to access that database do this:

class SomeThing < ActiveRecord::Base    establish_connection "sybasefu"    #.... end

One thing to check is if you have several models that need to connect to sybasefu, *each* one will open it's own connection. Unlike your "normal" models which share a single database connection. This was true for Rails 1.1.6 (and yes, I realize how old that is :). To get around it I did this:

class MySybaseClasses < ActiveRecord::Base    establish_connection "sybasefu" end

class Something < MySpaceClasses    #.... end

class SomethingElse < MySpaceClasses    #... end

That may or may not still be an issue, but it's something to check. If it isn't, let me know :slight_smile:

-philip