# Connect to two databases / Delegate authentication?

**URL:** <https://www.ruby-forum.com/t/connect-to-two-databases-delegate-authentication/81541>\
**Category:** Rails\
**Created:** [January 9, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/connect-to-two-databases-delegate-authentication/81541 "2007-01-09T19:44:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3d9bf3/32.png) [@codex](https://www.ruby-forum.com/u/codex)\
**Post date:** [January 9, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/connect-to-two-databases-delegate-authentication/81541/1 "2007-01-09T19:44:25Z")

</div>

Hello,

I need to write a Rails application with user authentication.

This is no problem so far, but the company that needs the rails  
application does have a large user database that is used for an already  
existing application.

In the new Rails application, there are four types of users with  
different rights. The existing users should be equal to one of these  
types.

When authenticating, the Rails application should first try to find the  
user in the own database. If this step fails, it should try to  
authenticate the user against the Oracle Database.

So is it possible to connect to a MySQL database for data storage and  
additionally connect to an Oracle DB for user authentication? Even if  
the database scheme in the Oracle DB is fixed, does not comply with  
ActiveRecord standards and can’t be changed?

Any help on this topic is appreciated.

---

<div class="post-metadata">

**Author:** ![codex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3d9bf3/32.png) [@codex](https://www.ruby-forum.com/u/codex)\
**Post date:** [January 9, 2007, 10:19pm UTC](https://www.ruby-forum.com/t/connect-to-two-databases-delegate-authentication/81541/2 "2007-01-09T22:19:13Z")

</div>

Code Xy wrote:

> Hello,
> 
> I need to write a Rails application with user authentication.
> 
> This is no problem so far, but the company that needs the rails  
> application does have a large user database that is used for an already  
> existing application.
> 
> In the new Rails application, there are four types of users with  
> different rights. The existing users should be equal to one of these  
> types.
> 
> When authenticating, the Rails application should first try to find the  
> user in the own database. If this step fails, it should try to  
> authenticate the user against the Oracle Database.
> 
> So is it possible to connect to a MySQL database for data storage and  
> additionally connect to an Oracle DB for user authentication? Even if  
> the database scheme in the Oracle DB is fixed, does not comply with  
> ActiveRecord standards and can’t be changed?
> 
> Any help on this topic is appreciated.

You can create another model that uses  
ActiveRecord::Base.establish\_connection (see api) to connect to your  
OracleDB, and then query that model if search in the Rails app DB fails.  
See also here:

[http://wiki.rubyonrails.com/rails/pages/HowtoUseMultipleDatabases](http://wiki.rubyonrails.com/rails/pages/HowtoUseMultipleDatabases)

---

<div class="post-metadata">

**Author:** ![codex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3d9bf3/32.png) [@codex](https://www.ruby-forum.com/u/codex)\
**Post date:** [January 10, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/connect-to-two-databases-delegate-authentication/81541/3 "2007-01-10T22:07:07Z")

</div>

Thanks, I did not know they cover this in the wiki!

FranÃ§ois Montel wrote:

> You can create another model that uses  
> ActiveRecord::Base.establish\_connection (see api) to connect to your  
> OracleDB, and then query that model if search in the Rails app DB fails.  
> See also here:
> 
> [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/HowtoUseMultipleDatabases)
