# Support for multiple database session

**URL:** <https://www.ruby-forum.com/t/support-for-multiple-database-session/186088>\
**Category:** Rails\
**Created:** [March 31, 2010, 1:07pm UTC](https://www.ruby-forum.com/t/support-for-multiple-database-session/186088 "2010-03-31T13:07:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitin\_k\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nitin\_k\_m](https://www.ruby-forum.com/u/nitin_k_m)\
**Post date:** [March 31, 2010, 1:07pm UTC](https://www.ruby-forum.com/t/support-for-multiple-database-session/186088/1 "2010-03-31T13:07:38Z")

</div>

Hi all,

I am working on a rails project. First I am giving a brief of what it  
does then I will tell what are issues I am facing.

This project is basically a reporting tool that gets data from database  
and generates report. I have different databases for different products  
with same structure (schema) for all. I want to have a drop down menu on  
the homepage where user can select which database he wants to connect  
and generate report for the selected database. I am connecting to  
selected database manually in application controller and using this as  
before\_filter in application.rb.

Problem is that user can select any database while logs in. When two  
users log in selecting different databases. The user who logs in later  
only database session for that user sustains and data from other  
database no longer accessible to user logged in first. Rather he also  
now gets data of 2nd database.

I must implement it correctly. Please suggest me how it can be done. I  
have 5 such databases to connect dynamically with each user always gets  
data from selected database.

Thanks a lot,  
Nitin.
