Multiple database login issue

Here is a problem which is quite mysterious to me,

I am having multiple database architecture, each user logs in with
organisation name/user name/password
There is a master database and a table ‘names’ which contains the names
of the database corresponding to each organisation name

I am using
ActiveRecord::Base.connection.execute(‘USE ‘+name_from
_master_db_table+’’)

to dynamically switch the database, also i am using act_as_authenticated
plugin to login the users

Now the issue is that i need to login twice to enter, also if i login in
a different browser with a different org name(which connects to a
different db ) the page in the initial browser gets logged out, All
these used to work fine when the session store was cookie based , now
that i have changed to active_record store, I am facing these issues,
any idea or suggestion on this would be helpful a lot.

On 9 Mar 2009, at 16:03, Shank Shaan wrote:

ActiveRecord::Base.connection.execute('USE '+name_from
these used to work fine when the session store was cookie based , now
that i have changed to active_record store, I am facing these issues,
any idea or suggestion on this would be helpful a lot.

well when you switch the database like that you’re probably leaving it
switched, so when the next request is handled it’s trying to get the
session from the wrong database.

Fred

Frederick C. wrote:

On 9 Mar 2009, at 16:03, Shank Shaan wrote:

ActiveRecord::Base.connection.execute('USE '+name_from
these used to work fine when the session store was cookie based , now
that i have changed to active_record store, I am facing these issues,
any idea or suggestion on this would be helpful a lot.

well when you switch the database like that you’re probably leaving it
switched, so when the next request is handled it’s trying to get the
session from the wrong database.

Fred

Thanks fred, but I am storing the db info in the cookie and using a
before filter in the application.rb, so I guess its some issue with
act_as_auth plugin?

Thanks so much fred for the reply, posted this question in many forums
but unfotunately, did not recieve even a single reply except yours.
thanks again.

I could not figure out why this issue appears, i donot thing the
before_filter from acts_as_auth runs before the before_filter that sets
the db

this is the order in application.rb

before_filter :connection
include AuthenticatedSystem
before_filter :login_from_cookie,:login_required

Struggling with this issue for over 2 weeks now I have temporarily
fixed this issue by making the sessions store in a single database for
all organisations by using
CGI::Session::ActiveRecordStore::Session.establish_connection, so not it
works fine with multiple db architecture.

Meanwhile one thing that I noticed was the session id in the request.env
was different from the one that shows up in the log

Processing HomeController#index (for 127.0.0.1 at 2009-03-11 13:02:07)
[GET]
Session ID: 97dfbf70c7839f876927fdb9f69ffe37

“HTTP_COOKIE”=>“_session_id=7e4a42b0acc8a333c2dc00fd64a644cb;
dbname=me_dev”, “HTTP_ACCEPT_CHARSET”=>“ISO-8859-1,utf-8;q=0.7,*;q=0.7”,
“REQUEST_URI”=>“http://localhost:3000/”,

I have no idea why this happens, may be someone can shed some light.

On 9 Mar 2009, at 17:54, shaan ss wrote:

well when you switch the database like that you’re probably leaving
it
switched, so when the next request is handled it’s trying to get the
session from the wrong database.

Fred

Thanks fred, but I am storing the db info in the cookie and using a
before filter in the application.rb, so I guess its some issue with
act_as_auth plugin?

The fact that it worked fine when the session store was cookie based
makes that seem unlikely. Perhaps the before_filter from acts_as_auth
runs before your before_filter that sets the db.

Fred