Multiple database support

Hi All,        Could you please help me getting a way to support multiple databases with rails application. I found that with ruby application we can connect only one database at a time by either specifying database information in database.yml file or overrriding it in activerecord subclasses.

My requirement is:

Suppose I have three databases: db1, db2, db3. All these three databases have same database schema (structure). When a user logs in to the application he will be asked to which database he wants to connect. And the application will be connected to selected database accordingly.

I am able to connect to databases dynamically using activerecord establish_connection method. But the problem is When user1 logs in and opt to connect to db1, he finds everything working properly. Now if user2 logs in and connects to database db2, user2 will find everything fine but now user1 also finds himself connected to db2 instead of db1. i.e. rails application connects to only one database at a time.

Is there a way to connect to multiple databases based on different user sessions. Please suggest me method to do so.

Thanks Nitin