# Connecting to sessions table in another database

**URL:** <https://www.ruby-forum.com/t/connecting-to-sessions-table-in-another-database/184705>\
**Category:** Rails\
**Created:** [March 7, 2010, 2:57am UTC](https://www.ruby-forum.com/t/connecting-to-sessions-table-in-another-database/184705 "2010-03-07T02:57:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pakothawade](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pakothawade](https://www.ruby-forum.com/u/pakothawade)\
**Post date:** [March 7, 2010, 2:57am UTC](https://www.ruby-forum.com/t/connecting-to-sessions-table-in-another-database/184705/1 "2010-03-07T02:57:01Z")

</div>

I have two applications, appA and appB. I want to use single sign on  
for both the apps.  
Meaning, if a user logs in to appA, he dont have to login to appB and  
conversely, if a user logged out of appA, it logs him out of appB too.  
Just like in google’s various products.

I created the sessions table in appA. How do i access the sessions  
table in appB.  
I tried to put ActiveRecord::Base.establish\_connection :appA in the  
config\initializers\session\_store.rb of appB,  
but that connects the whole appB application to appA database. I only  
want to access the sessions table.

How do i do it?

database.yml of appB has:  
appA:  
adapter: mysql  
database: appa\_dev  
pool: 5  
username: app\_user  
password: app\_pwd  
host: localhost  
Thanks,  
Pratik

---

<div class="post-metadata">

**Author:** ![pakothawade](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pakothawade](https://www.ruby-forum.com/u/pakothawade)\
**Post date:** [March 8, 2010, 7:09am UTC](https://www.ruby-forum.com/t/connecting-to-sessions-table-in-another-database/184705/2 "2010-03-08T07:09:42Z")

</div>

On Mar 6, 5:55 pm, tispratik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but that connects the whole appB application to appA database. I only  
> want to access the sessions table.
> 
> How do i do it?  
> …  
> I do not have an answer to your specific question, but I have 2 Rails  
> apps that share the session and thus feature a single sign-on. But I  
> use session in cookies, not session in a db table.

---

<div class="post-metadata">

**Author:** ![pakothawade](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pakothawade](https://www.ruby-forum.com/u/pakothawade)\
**Post date:** [March 8, 2010, 8:33am UTC](https://www.ruby-forum.com/t/connecting-to-sessions-table-in-another-database/184705/3 "2010-03-08T08:33:59Z")

</div>

On Sat, Mar 6, 2010 at 5:55 PM, tispratik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but that connects the whole appB application to appA database. I only  
> password: app\_pwd  
> host: localhost  
> Thanks,  
> Pratik

Pratik, have you considered OpenID or CAS? If not, I would like into  
those  
as possible  
solutions as well.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![pakothawade](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pakothawade](https://www.ruby-forum.com/u/pakothawade)\
**Post date:** [March 8, 2010, 7:35pm UTC](https://www.ruby-forum.com/t/connecting-to-sessions-table-in-another-database/184705/4 "2010-03-08T19:35:27Z")

</div>

On Sat, Mar 6, 2010 at 5:55 PM, tispratik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I created the sessions table in appA. How do i access the sessions  
> table in appB.  
> I tried to put ActiveRecord::Base.establish\_connection :appA in the  
> config\initializers\session\_store.rb of appB,  
> but that connects the whole appB application to appA database. I only  
> want to access the sessions table.

Then you need to use establish\_connection _only_ in the model that’s  
accessing that table.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
