# Two databases

**URL:** <https://www.ruby-forum.com/t/two-databases/113111>\
**Category:** Rails\
**Created:** [August 27, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/two-databases/113111 "2007-08-27T19:24:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@joshua](https://www.ruby-forum.com/u/joshua)\
**Post date:** [August 27, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/two-databases/113111/1 "2007-08-27T19:24:40Z")

</div>

Hello all, I’ve got a question. I’m writing a RoR app for a client and  
they need me to use two databases, one a mssql database the other a  
mysql database. The mssql database will hold the username/password  
values. Once I connect to the mssql database, I’ll need to change to  
another database to query the information in the reporting software. Any  
tips on configuring this?

---

<div class="post-metadata">

**Author:** ![joshua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@joshua](https://www.ruby-forum.com/u/joshua)\
**Post date:** [August 27, 2007, 11:54pm UTC](https://www.ruby-forum.com/t/two-databases/113111/2 "2007-08-27T23:54:36Z")

</div>

If all you’re using the MSSQL database for is a username and password,  
you ought to make the MySQL database the primary database. In  
database.yml, add configuration for your MSSQL server. It will look  
something like:

mssql\_connection:  
adapter: sqlserver  
database: dbmydatabase  
host: [sqlserver.domain.com](http://sqlserver.domain.com)  
username: user  
password: secret

Then, generate a model in your project and insert code akin to:

class LoginInfo \< ActiveRecord::Base  
set\_table\_name “user\_info”  
establish\_connection :mssql\_connection

def fetch\_username  
# code to get username here  
end

def fetch\_password  
# code to get password here  
end  
end

Then you should be able to call UserInfo.fetch\_username from within  
your app and the username will be returned.

On Aug 27, 11:24 am, Joshua T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![joshua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@joshua](https://www.ruby-forum.com/u/joshua)\
**Post date:** [August 28, 2007, 2:48am UTC](https://www.ruby-forum.com/t/two-databases/113111/3 "2007-08-28T02:48:01Z")

</div>

Joshua T. wrote:

> Hello all, I’ve got a question. I’m writing a RoR app for a client and  
> they need me to use two databases, one a mssql database the other a  
> mysql database. The mssql database will hold the username/password  
> values. Once I connect to the mssql database, I’ll need to change to  
> another database to query the information in the reporting software. Any  
> tips on configuring this?

If the only thing you are using the SQL Server for is authentication,  
wrap it with a quick web service and just use that instead of a rails  
model.
