Martin Berli
2007-Jun-02 08:52 UTC
establish_connection does not raise exception for wrong password
Hello, When changing the default yaml-defined-connection via the establish_connection in, say, a login controller (we are using user-level access to our database), wrong credentials are not immediately notified (no exception is raised). Instead, this happens only at the first database access after the establish_connection call: ActiveRecord::Base.establish_connection(...<wrong pwd>) rescue ... # not getting here ActiveRecord::Base.establish_connection(...<wrong pwd>) SomeTable.fetchData rescue ... # getting here, $! containing (Oracle) database error message, saying pwd is wrong Is this a bug, or a feature? Thanks for any hints, Martin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Jun-02 09:21 UTC
Re: establish_connection does not raise exception for wrong
Martin Berli wrote:> Hello, > > When changing the default yaml-defined-connection via the > establish_connection in, > say, a login controller (we are using user-level access to our > > Thanks for any hints, > MartinEstablish connection have no exception saying that the pwd is wrong. ------------- The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError may be returned on an error. ------------- But you can use the connected? boolean method to know if you connected to the database or not -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> > But you can use the connected? boolean method to know if you connected > to the database or notThanks for your reply. Your "solution" works, but the connected? method does not return false in my case, it raises an exception. Conceptually, I would prefer the boolean value... Regards, Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Jun-02 10:40 UTC
Re: establish_connection does not raise exception for wrong
Martin wrote:> Jamal Soueidan wrote: > >> >> But you can use the connected? boolean method to know if you connected >> to the database or not > > Thanks for your reply. Your "solution" works, but the connected? > method does not return false in my case, it raises an exception. > Conceptually, I would prefer the boolean value... > > Regards, > MartinWhat exception does it raise? ------------------------------------------ active? Is this connection active and ready to perform queries? Try it, maybe this doesn''t raise any exception. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> What exception does it raise? > > ------------------------------------------ > > active? > Is this connection active and ready to perform queries? > > Try it, maybe this doesn''t raise any exception.Now we are going details... actually, I already used ActiveRecord::Base.connection.active? I found out that this raises an OCIException, if called after an establish_connection with wrong credentials. ActiveRecord::Base.connected? always returns false for me, even if the credentials are correct... Btw, is there an easy way to find out what Exception was raised when giving an empty rescue line? Regards, Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Jun-02 15:55 UTC
Re: establish_connection does not raise exception for wrong
Martin wrote:> Jamal Soueidan wrote: > >> What exception does it raise? >> dentials are correct... > > Btw, is there an easy way to find out what Exception was > raised when giving an empty rescue line? >What do you mean empty rescue line?> Regards, > Martin-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> What do you mean empty rescue line?OK, I had a look at the documentation now, the correct description is "write a rescue clause with no parameter list" This defaults to StandardError. I would then like to find out which subtype of StandardError was caught. regards, martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Jun-02 19:34 UTC
Re: establish_connection does not raise exception for wrong
Martin wrote:> Jamal Soueidan wrote: > >> What do you mean empty rescue line? > > OK, I had a look at the documentation now, the correct > description is > > "write a rescue clause with no parameter list" > > This defaults to StandardError. I would then like to find > out which subtype of StandardError was caught. > > > regards, > martinIf you write rescue without any parameter list you would catch all the exception as you already know now... I think you can still know which exception occurred by using one method, cannot remember.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-02 21:09 UTC
Re: establish_connection does not raise exception for wrong
On Jun 2, 2007, at 3:34 PM, Jamal Soueidan wrote:> Martin wrote: >> Jamal Soueidan wrote: >> >>> What do you mean empty rescue line? >> >> OK, I had a look at the documentation now, the correct >> description is >> >> "write a rescue clause with no parameter list" >> >> This defaults to StandardError. I would then like to find >> out which subtype of StandardError was caught. >> >> >> regards, >> martin > > If you write rescue without any parameter list you would catch all the > exception as you already know now... > > I think you can still know which exception occurred by using one > method, > cannot remember..begin raise NameError, "something went wrong" rescue => e puts "Caught: #{e.class.name}" end rescue => e is exactly equivalent to: rescue StandardError => e If you need to catch more than StandardError, you can use: rescue Exception => e Or catch some other branch of the Exception hierarchy rescue ScriptError => e # subclass of Exception rescue LoadError => e # subclass of ScriptError Or even less than StandardError rescue IOError => e # subclass of StandardError rescue EOFError => e # subclass of IOError And, of course, ''e'' is just a local variable so use your favorite name if ''e'' doesn''t feel right (but it is a very common idiom). -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---