Hi, I''m almost finished writing my first real application in Rails.  
Everything has gone smoothly up to this point, but I''m having some  
trouble simultaneously querying multiple databases. I followed the  
advice given by Michael Koziarski on this blog http://blog.amber.org/ 
2005/06/30/lost-in-multiple-rails/ and I added the following to  
environment.rb.
Labtrol.establish_connection "labtroll"
and the following to database.yml
labtroll:
   adapter: mysql
   database: labtroll
   host: localhost
   username: devel
   password: xxxxxxxx
Labtrol is a model providing a few basic queries on the SECOND  
database I''m trying to query.
Here''s where things get weird. Upon the first load of my page, all  
queries succeed, and both databases are connected to with no  
problems. From the second page load on, I get the following error  
message:
ActiveRecord::StatementInvalid in Alpkem#runcal
Table ''alpkem.sample'' doesn''t exist: SELECT DISTINCT
SA_CLTNO AS
client FROM sample WHERE
                          SA_SAMPNO = 263802
/app/models/labtrol.rb:7:in `get_client''
app/controllers/alpkem_controller.rb:12:in `runcal''
script/server:48
Basically, when I''m trying to run a query on my database named  
Labtrol, the database named Alpkem is being queried instead. I have a  
suspicion that this is due to some caching mechanism, which would  
explain why it happens after the first page load; however, my  
RAILS_ENV indicates that I''m using the development environment, which  
has the following settings:
Dependencies.mechanism                             = :load
ActionController::Base.consider_all_requests_local = true
ActionController::Base.perform_caching             = false
BREAKPOINT_SERVER_PORT = 42531
Looks like caching is turned off. If anybody could help me solve this  
problem, I can wrap this program up.
Thanks,
Travis
On 9/12/05, Travis Whitton <twhitton-IuspszFyyTGGw+nKnLezzg@public.gmane.org> wrote:> > Hi, I''m almost finished writing my first real application in Rails. > Everything has gone smoothly up to this point, but I''m having some > trouble simultaneously querying multiple databases. I followed the > advice given by Michael Koziarski on this blog http://blog.amber.org/ > 2005/06/30/lost-in-multiple-rails/ and I added the following to > environment.rb. > > Labtrol.establish_connection "labtroll" > > and the following to database.yml > > labtroll: > adapter: mysql > database: labtroll > host: localhost > username: devel > password: xxxxxxxxHi, not sure why this doesn''t work, I do it a bit differently, to use your example this would be: Labtrol.establish_connection( :adapter => mysql, :host => localhost, :username => devel, :password => xxx, :database => labtroll ) placed in the same file as the Labtrol class (following the class definition). it does not confuse databases. it only makes webrick crash from time to time ;-) (by the way, not sure why it''s Labtrol and labtroll, but probably your problem does not have much to do with a misspelling of l''s :-) ) -- Agnieszka Figiel _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks very much! That fixed it. As far as the mismatched naming, that''s just a quirk of the proper name of the system I''m interacting with verses the name of the database. Now to finish my app... On Sep 13, 2005, at 9:01 AM, Agnieszka Figiel wrote:> > > On 9/12/05, Travis Whitton <twhitton-IuspszFyyTGGw+nKnLezzg@public.gmane.org> wrote: > Hi, I''m almost finished writing my first real application in Rails. > Everything has gone smoothly up to this point, but I''m having some > trouble simultaneously querying multiple databases. I followed the > advice given by Michael Koziarski on this blog http://blog.amber.org/ > 2005/06/30/lost-in-multiple-rails/ and I added the following to > environment.rb. > > Labtrol.establish_connection "labtroll" > > and the following to database.yml > > labtroll: > adapter: mysql > database: labtroll > host: localhost > username: devel > password: xxxxxxxx > > Hi, > > not sure why this doesn''t work, I do it a bit differently, to use > your example this would be: > > Labtrol.establish_connection( > :adapter => mysql, > :host => localhost, > :username => devel, > :password => xxx, > :database => labtroll > ) > > placed in the same file as the Labtrol class (following the class > definition). it does not confuse databases. it only makes webrick > crash from time to time ;-) > (by the way, not sure why it''s Labtrol and labtroll, but probably > your problem does not have much to do with a misspelling of l''s :-) ) > > -- > Agnieszka Figiel > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails