hi all! i''m currently working on a rails app that needs to access other databases via user defined ODBC connections. i''m using the latest rails-odbc gem on rails 1.2.2 (windows). while DSN driven connections seem to work fine it''s a bit inefficient because of the need to define the DSN''s on the server and then add them in the rails app. so i was hoping to use connection strings directly. but whenever i try putting in a connection string the connection fails with the error "Invalid string or buffer length" an example string i was using: Driver={SQL Server};Host=myhostname;Database=mydbname;Uid=myusername;Pwd=mypassword any ideas how to get this working? -- 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 -~----------~----~----~----~------~----~------~--~---
I use a dastabase.yml file like this: development: adapter: sqlserver mode: ODBC dsn: Driver={SQL Server};Server=MyMachine;Database=my_database As far as I know, it should work with most dsn strings. Tom On 23/04/07, neongrau __ <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hi all! > > i''m currently working on a rails app that needs to access other > databases via user defined ODBC connections. > > i''m using the latest rails-odbc gem on rails 1.2.2 (windows). > > while DSN driven connections seem to work fine it''s a bit inefficient > because of the need to define the DSN''s on the server and then add them > in the rails app. > so i was hoping to use connection strings directly. but whenever i try > putting in a connection string the connection fails with the error > "Invalid string or buffer length" > > an example string i was using: > > Driver={SQL > Server};Host=myhostname;Database=mydbname;Uid=myusername;Pwd=mypassword > > any ideas how to get this working? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Tom Ward wrote:> I use a dastabase.yml file like this: > > development: > adapter: sqlserver > mode: ODBC > dsn: Driver={SQL Server};Server=MyMachine;Database=my_database > > As far as I know, it should work with most dsn strings. > > Tomthis only seem to work with the sqlserver adapter in odbc mode. but i need to use the rails-odbc adapter (to support all odbc databases including oracle). i have this in a (dummy) model establish_connection(:adapter => ''odbc'', :dsn => connection_options.dsn, :username => connection_options.username, :password => connection_options.password, :trace => connection_options.trace, :emulate_booleans => connection_options.emulate_booleans, :convert_numeric_literals => connection_options.convert_numeric_literals) but as soon as i use a connection string instead of a system dsn it ends with this error: ODBC::Error: S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string or buffer length from c:/ruby/lib/ruby/gems/1.8/gems/odbc-rails-1.4/lib/active_record/connection_adapters/odbc_adapter.rb:48:in `initialize'' from c:/ruby/lib/ruby/gems/1.8/gems/odbc-rails-1.4/lib/active_record/connection_adapters/odbc_adapter.rb:48:in `connect'' from c:/ruby/lib/ruby/gems/1.8/gems/odbc-rails-1.4/lib/active_record/connection_adapters/odbc_adapter.rb:48:in `odbc_connection'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:267:in `send'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:267:in `connection_without_query_cache='' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/query_cache.rb:54:in `connection='' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:235:in `retrieve_connection'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'' the error causing line (48) in odbc_adapter.rb is: conn = ODBC::connect(dsn, username, password) i can''t get that to connect properly and i still couldn''t figure out what code is used for that "ODBC::connect" it can''t be the connect method from odbc.rb because that would work :S (i manually verified that it splits the dsn if it''s a connecton string) -- 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 -~----------~----~----~----~------~----~------~--~---
What dsn parameter is used in the call ODBC::connect(dsn, username, password)? Tom On 24/04/07, neongrau __ <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Tom Ward wrote: > > I use a dastabase.yml file like this: > > > > development: > > adapter: sqlserver > > mode: ODBC > > dsn: Driver={SQL Server};Server=MyMachine;Database=my_database > > > > As far as I know, it should work with most dsn strings. > > > > Tom > > this only seem to work with the sqlserver adapter in odbc mode. > but i need to use the rails-odbc adapter (to support all odbc databases > including oracle). > > i have this in a (dummy) model > establish_connection(:adapter => ''odbc'', > :dsn => connection_options.dsn, > :username => connection_options.username, > :password => connection_options.password, > :trace => connection_options.trace, > :emulate_booleans => > connection_options.emulate_booleans, > :convert_numeric_literals => > connection_options.convert_numeric_literals) > > > but as soon as i use a connection string instead of a system dsn it ends > with this error: > > ODBC::Error: S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string > or buffer length > from > c:/ruby/lib/ruby/gems/1.8/gems/odbc-rails-1.4/lib/active_record/connection_adapters/odbc_adapter.rb:48:in > `initialize'' > from > c:/ruby/lib/ruby/gems/1.8/gems/odbc-rails-1.4/lib/active_record/connection_adapters/odbc_adapter.rb:48:in > `connect'' > from > c:/ruby/lib/ruby/gems/1.8/gems/odbc-rails-1.4/lib/active_record/connection_adapters/odbc_adapter.rb:48:in > `odbc_connection'' > from > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:267:in > `send'' > from > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:267:in > `connection_without_query_cache='' > from > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/query_cache.rb:54:in > `connection='' > from > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:235:in > `retrieve_connection'' > from > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in > `connection'' > > the error causing line (48) in odbc_adapter.rb is: > conn = ODBC::connect(dsn, username, password) > > i can''t get that to connect properly and i still couldn''t figure out > what code is used for that "ODBC::connect" it can''t be the connect > method from odbc.rb because that would work :S (i manually verified that > it splits the dsn if it''s a connecton string) > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Tom Ward wrote:> What dsn parameter is used in the call ODBC::connect(dsn, username, > password)? > > Tomas DSN for example "Driver={SQL Server};Server=myhostname;Database=mydatabase;Uid=foo;Pwd=bar;" (makes no difference if user credentials are passed directly or within the connection string or if i write DBI:ODBC:Driver={SQL Server}) and the connection string is correct since i can successfully connect with it using DBI -> db=DBI.connect("DBI:ODBC:Driver={SQL Server};Server=myhostname;Database=mydatabase ;Uid=foo;Pwd=bar;") => #<DBI::DatabaseHandle:0x47242ec @trace_mode=2, @handle=#<DBI::DBD::ODBC::Data base:0x4723900 @attr={}, @handle=#<ODBC::Database:0x4723fcc>>, @trace_output=#<I O:0x2886ba0>> i guess i''ll better drop odbc totally and just support the default connection adapters and system dsn. :( -- 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 -~----------~----~----~----~------~----~------~--~---
i just hacked in the relevant code logic from odbc.rb into the odbc_adapter.rb and now it seems to work :D driver_attrs = dsn.split('';'') if driver_attrs.length.eql?(1) # try system dsn conn = ODBC::connect(dsn, username, password) else # try connection string driver = ::ODBC::Driver.new driver.name = ''DSN-less'' driver_attrs.each do |param| attr = param.split(''='') driver.attrs[attr[0]] = attr[1] if attr.length.eql?(2) end conn = ::ODBC::Database.new.drvconnect(driver) end conn.autocommit = true i need to test this a bit and then i''ll ask the maintainer to include this into the next release -- 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 -~----------~----~----~----~------~----~------~--~---