# Oracle and MySql simultaneously from rails app

**URL:** <https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607>\
**Category:** Rails\
**Created:** [May 16, 2006, 3:19am UTC](https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607 "2006-05-16T03:19:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [May 16, 2006, 3:19am UTC](https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607/1 "2006-05-16T03:19:47Z")

</div>

I searched this site on Oracle && MySql, nothing came up, so perhaps  
this is a new topic for this forum.

I’d like to access two databases from the same application  
simultaneously (well, more precisely, in rapid succession, calling one  
first and then the other, as any “joins” will be done in the application  
code).

One database is in MySql, the other is Oracle.

Possible? Howto? THANKS

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [May 16, 2006, 4:12am UTC](https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607/2 "2006-05-16T04:12:21Z")

</div>

Possible.

Howto:

1. Install the Rails-Oracle connection library(download from  
[http://rubyforge.org/projects/ruby-oci8](http://rubyforge.org/projects/ruby-oci8) and install)
2. Add in this into database.yml (or something like it):

my\_oracle\_connection:  
adapter: oci  
username: ruby  
password: ruby  
host: RAILS

1. Create a model:

class MyOracleModel \< ActiveRecord::Base  
set\_table\_name “my\_oracle\_table\_name”  
establish\_connection “my\_oracle\_connection”  
end

1. Use the model as any other ActiveRecord model

2. Mix and match with your MySQL models, only be careful with the  
relationships.

da plutes wrote:

> Possible? Howto? THANKS

–  
Sau S.

[http://blog.saush.com](http://blog.saush.com)  
[http://www.projectible.com](http://www.projectible.com)  
[http://jaccal.sourceforge.net](http://jaccal.sourceforge.net)

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [May 16, 2006, 7:21pm UTC](https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607/3 "2006-05-16T19:21:11Z")

</div>

Thank you Sau S…

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [May 17, 2006, 8:00am UTC](https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607/4 "2006-05-17T08:00:23Z")

</div>

…never mind w.r.t. previous – I put the tnsnames.ora defined name  
(which happens to be the same as the database name) in the host  
parameter and it works.

onwards

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [May 17, 2006, 6:17am UTC](https://www.ruby-forum.com/t/oracle-and-mysql-simultaneously-from-rails-app/60607/5 "2006-05-17T06:17:21Z")

</div>

I installed the Rails-Oracle connection library. Walking before I run  
– first I am trying to get Oracle up on Rails before I do both MySql &  
Oracle. So, this is in database.yml:

development:  
adapter: oci  
database: dbname  
username: user  
password: passwd  
host: hostname

I am able to connect to the Oracle database using SqlPlus and run  
queries – for instance this succeeds:

sqlplus user/passwd@dbname

But Rails seems to not see Oracle. When I try to generate a scaffold for  
a controller that depends on a table in this database, I get:

ORA-12154: TNS:could not resolve service name

…and the controller and views are not created.

The service name for the database seems to be listed properly in my  
tnsnames.ora file, which I expect given that I am able to connect via  
sqlplus.

Any ideas?
