Hi, I have a need to connect to different databases based on information I retrieve from a master db. I''m using ruby under Win XP, connecting to a sqlserver db with odbc. The odd thing is that I can connect without any problem to a database as long as I setup the "change the default database to" option in the creation of the windows odbc data source. But if I don''t specify a default database - even though I specify the :database when I connect, it doesn''t find the database. The code couldn''t be more straightforward (I guess unless it worked!) foo.establish_connection( :adapter => "sqlserver", :mode => "odbc", :dsn => "production", :database => "dagoods", :username => "theman", :password => "secret" ) I''ve tried different types of dsns and fooled with everything I can think of - any ideas?? thanks in advance! Regards Charlie -- 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 -~----------~----~----~----~------~----~------~--~---
Charlie Walden
2007-Jan-19 18:15 UTC
Re: Using ODBC under windows without "default database"
Charlie Walden wrote:> Hi, > > I have a need to connect to different databases based on information I > retrieve from a master db. I''m using ruby under Win XP, connecting to a > sqlserver db with odbc. > > The odd thing is that I can connect without any problem to a database as > long as I setup the "change the default database to" option in the > creation of the windows odbc data source. But if I don''t specify a > default database - even though I specify the :database when I connect, > it doesn''t find the database. > > The code couldn''t be more straightforward (I guess unless it worked!) > > foo.establish_connection( > :adapter => "sqlserver", > :mode => "odbc", > :dsn => "production", > :database => "dagoods", > :username => "theman", > :password => "secret" > ) > > I''ve tried different types of dsns and fooled with everything I can > think of - any ideas?? > > thanks in advance! > > Regards > CharlieDuh - solved it and of course it''s obvious, but I''ll leave it here in case someone else makes the same mistake. Since no db was specified, you have to send a sql "use" statement over. so executing the following does the trick: Foo.connection.select_value("use databasename") -- 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 -~----------~----~----~----~------~----~------~--~---