New to rails. Installed rails on my XP desktop, and setup my first app that will use an existing SQLServer database. I am able to connect to SQLServer using odbc with following code. require ''rubygems'' require ''ActiveRecord'' ActiveRecord::Base.establish_connection( :adapter => ''sqlserver'', :mode => ''odbc'', :dsn => ''Driver={SQL Server};Server=<server>;Database=<db>'', :username => ''uid'', :password => ''pwd'' ) class src <ActiveRecord::Base set_table_name ''Source'' set_primary_key ''IDSource'' end s = [] s = Source.find(1) puts s.SourceName I was able to connect and the code behaves as expected. However when I try to use database.yml to specify the same connection information, I am unable to connect using script/dbconsole. #database.yml development: adapter : sqlserver mode : odbc dsn : Driver={SQL Server};Server=<server>;Database=<db> username : <uid> password : <pwd> When I start script/dbconsole, the error is D:\work\rails\job>ruby script/dbconsole Unknown command-line client for <db>. Submit a Rails patch to add support! My assumption is that my database.yml does not describe the connection properly, since I am able to connect directly using establish_connection method. Is there any documentation on how to specify a odbc connection in yml for rails? Here is the list of installed gems :: D:\work\rails\job>gem list *** LOCAL GEMS *** actionmailer (2.3.2, 2.0.0) actionpack (2.3.2, 2.0.0) activerecord (2.3.2, 2.0.0) activerecord-sqlserver-adapter (2.2.18) activeresource (2.3.2) activesupport (2.3.2, 2.0.0) dbd-odbc (0.2.4) dbi (0.4.1) deprecated (2.0.1) fxri (0.3.7, 0.3.6) fxruby (1.6.19, 1.6.12) hpricot (0.8.1, 0.6) log4r (1.0.5) ptools (1.1.6) rails (2.3.2) rake (0.8.7, 0.7.3) sources (0.0.1) test-unit (2.0.2) win32-api (1.4.2, 1.0.4) win32-clipboard (0.5.1, 0.4.3) win32-dir (0.3.4, 0.3.2) win32-eventlog (0.5.0, 0.4.6) win32-file (0.6.1, 0.5.4) win32-file-stat (1.3.3, 1.2.7) win32-process (0.6.0, 0.5.3) win32-sapi (0.1.4) win32-sound (0.4.1) windows-api (0.3.0, 0.2.0) windows-pr (1.0.5, 0.7.2) Thanks and appreciate any help leading to the resolution. -- Posted via http://www.ruby-forum.com/.
On Jun 8, 4:23 pm, Steve Dc <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> New to rails. Installed rails on my XP desktop, and setup my first app > that will use an existing SQLServer database. I am able to connect to > SQLServer using odbc with following code. > > require ''rubygems'' > require ''ActiveRecord'' > > ActiveRecord::Base.establish_connection( > :adapter => ''sqlserver'', > :mode => ''odbc'', > :dsn => ''Driver={SQL Server};Server=<server>;Database=<db>'', > :username => ''uid'', > :password => ''pwd'' > ) > > class src <ActiveRecord::Base > set_table_name ''Source'' > set_primary_key ''IDSource'' > end > > s = [] > s = Source.find(1) > puts s.SourceName > > I was able to connect and the code behaves as expected. However when I > try to use database.yml to specify the same connection information, I am > unable to connect using script/dbconsole.script/dbconsole is just a handy shortcut for opening a connection to the database using whatever command line tool that database provides (eg with mysql it just runs the mysql utility). What rails is telling you here is that it doesn''t know what it should launch for this kind of database (which isn''t entirely surprising what with the sqlserver being unbundled from rails). This isn''t actually related to the ability to connect to the database from a rails app though. Fred> > #database.yml > development: > adapter : sqlserver > mode : odbc > dsn : Driver={SQL Server};Server=<server>;Database=<db> > username : <uid> > password : <pwd> > > When I start script/dbconsole, the error is > D:\work\rails\job>ruby script/dbconsole > Unknown command-line client for <db>. Submit a Rails patch to add > support! > > My assumption is that my database.yml does not describe the connection > properly, since I am able to connect directly using establish_connection > method. Is there any documentation on how to specify a odbc connection > in yml for rails? > > Here is the list of installed gems :: > D:\work\rails\job>gem list > > *** LOCAL GEMS *** > > actionmailer (2.3.2, 2.0.0) > actionpack (2.3.2, 2.0.0) > activerecord (2.3.2, 2.0.0) > activerecord-sqlserver-adapter (2.2.18) > activeresource (2.3.2) > activesupport (2.3.2, 2.0.0) > dbd-odbc (0.2.4) > dbi (0.4.1) > deprecated (2.0.1) > fxri (0.3.7, 0.3.6) > fxruby (1.6.19, 1.6.12) > hpricot (0.8.1, 0.6) > log4r (1.0.5) > ptools (1.1.6) > rails (2.3.2) > rake (0.8.7, 0.7.3) > sources (0.0.1) > test-unit (2.0.2) > win32-api (1.4.2, 1.0.4) > win32-clipboard (0.5.1, 0.4.3) > win32-dir (0.3.4, 0.3.2) > win32-eventlog (0.5.0, 0.4.6) > win32-file (0.6.1, 0.5.4) > win32-file-stat (1.3.3, 1.2.7) > win32-process (0.6.0, 0.5.3) > win32-sapi (0.1.4) > win32-sound (0.4.1) > windows-api (0.3.0, 0.2.0) > windows-pr (1.0.5, 0.7.2) > > Thanks and appreciate any help leading to the resolution. > -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> On Jun 8, 4:23�pm, Steve Dc <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> � :dsn => ''Driver={SQL Server};Server=<server>;Database=<db>'', >> s = Source.find(1) >> puts s.SourceName >> >> I was able to connect and the code behaves as expected. However when I >> try to use database.yml to specify the same connection information, I am >> unable to connect using script/dbconsole. > > script/dbconsole is just a handy shortcut for opening a connection to > the database using whatever command line tool that database provides > (eg with mysql it just runs the mysql utility). What rails is telling > you here is that it doesn''t know what it should launch for this kind > of database (which isn''t entirely surprising what with the sqlserver > being unbundled from rails). This isn''t actually related to the > ability to connect to the database from a rails app though. > > FredThanks Fred. I will ignore this issue and move on. But next this is where I am stuck. I have the following code in app/controllers/processjobs_controller.rb # class ProcessJobsController <ApplicationController def index @ProcessJobs = ProcessJobs.find(:all) end end # This is my route file .. ActionController::Routing::Routes.draw do |map| map.resources :ProcessJobs map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end When I point my browser to localhost:3000/ProcessJobs, this is what I see in the log file. When I see the first few lines, it appears that rails is trying to logon as ''sa''. The database.yml file has the following contents. development: adapter : sqlserver mode : odbc dsn : Driver={SQL Server};Server=<server> database : ODS username : <definitely_not_sa> password : <pwd> The log file also shows this : NameError (uninitialized constant ProcessJobsController) Not sure how to interpret this message. The contents of the log file follows: /!\ FAILSAFE /!\ Mon Jun 08 08:42:58 -0500 2009 Status: 500 Internal Server Error 28000 (18456) [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user ''sa''. d:/ruby/lib/ruby/gems/1.8/gems/dbd-odbc-0.2.4/lib/dbd/odbc/driver.rb:36:in `connect'' d:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi/handles/driver.rb:33:in `connect'' d:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:142:in `connect'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.18/lib/active_record/connection_adapters/sqlserver_adapter.rb:775:in `connect'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.18/lib/active_record/connection_adapters/sqlserver_adapter.rb:211:in `initialize'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.18/lib/active_record/connection_adapters/sqlserver_adapter.rb:26:in `new'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.18/lib/active_record/connection_adapters/sqlserver_adapter.rb:26:in `sqlserver_connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'' d:/ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:9:in `cache'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:28:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb:24:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:93:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:9:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `synchronize'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:46:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:40:in `each'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:40:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb:17:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/content_length.rb:13:in `call'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb:46:in `service'' d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' d:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' d:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'' d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb:13:in `run'' d:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111 d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' script/server:3 Processing ActionController::Base#index (for 127.0.0.1 at 2009-06-08 13:04:12) [GET] NameError (uninitialized constant ProcessJobsController): d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' d:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' d:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'' d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' d:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' Rendered rescues/_trace (109.0ms) Rendered rescues/_request_and_response (0.0ms) Rendering rescues/layout (internal_server_error) -- Posted via http://www.ruby-forum.com/.