Forum: Ruby on Rails Multiple DB connections not working after first call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
55742d912a9003080d202c5522d4de00?d=identicon&s=25 rails (Guest)
on 2005-11-30 22:55
(Received via mailing list)
Hello!

I've looked through the mailing list archives, but havn't found a viable
answer for this question.  I would like to have my rails app handle a
couple tables in a legacy database.  Looking at the wiki, comments in
the
rails code, and searching for past comments on this list, I've tried two
different methods that are both broken.  At least for PostgreSQL, I
havn't
testing this bug with any other databases.

First method is establishing the connection in environment.rb like such:

   MyModel.establish_connection :my_db

This only works the first time if the page loaded uses MyModel.  All
subsequent calls defaults to the connection for ActiveRecord::Base.  I
can
see the entry in active_connections, but it doesn't seem to be used.

Second option is putting the extablish_connection directly in the
my_model.rb file.

   class MyModel < ActiveRecord::Base
     establish_connection :my_db
   end

This works.. until you start having your db complain about too many
connections.  It will open a new database connection each time you
access
the model, and it leaves all previous connections open.  Taking a look
at
active_connections will show multiple entries for MyModel.

Does anyone have a solution that will work, and won't make multiple
connections that will never be used again?

Thanks for any help,
Ken...
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-30 23:03
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 30, 2005, at 1:51 PM, Ken Bowley wrote:
>
>   MyModel.establish_connection :my_db
>
> This only works the first time if the page loaded uses MyModel.
> All subsequent calls defaults to the connection for
> ActiveRecord::Base.  I can see the entry in active_connections, but
> it doesn't seem to be used.

This was fixed in http://dev.rubyonrails.org/ticket/2996

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDjiEEAQHALep9HFYRAjEAAKC6NAp2UfRXMsdTj3u/Af3hEUvc8QCfXEls
YUeLL3a4HPezp0ayAPBSHh4=
=Ti8R
-----END PGP SIGNATURE-----
55742d912a9003080d202c5522d4de00?d=identicon&s=25 rails (Guest)
on 2005-11-30 23:40
(Received via mailing list)
On Wed, 30 Nov 2005, Jeremy Kemper wrote:

> This was fixed in http://dev.rubyonrails.org/ticket/2996
>
> jeremy

Thank you!  I've filed a bug report with Debian in the hopes that the
fix
will make it into the official Debian packages soon.
This topic is locked and can not be replied to.