SQLServer 2008 and Windows XP

I'm trying to connct to an MSSQLserver 2008 on a WinXP box.

$ ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]

$ rails --version Rails 3.0.1

$ gem list --local

*** LOCAL GEMS ***

abstract (1.0.0) actionmailer (3.0.1, 3.0.0) actionpack (3.0.1, 3.0.0) activemodel (3.0.1, 3.0.0) activerecord (3.0.1) activerecord-sqlserver-adapter (3.0.5) activeresource (3.0.1, 3.0.0) activesupport (3.0.1, 3.0.0, 1.4.4) arel (2.0.2, 1.0.1) builder (2.1.2) bundler (1.0.3) cgi_multipart_eof_fix (2.5.0) dbi (0.4.5) deprecated (3.0.0, 2.0.1) erubis (2.6.6) fastthread (1.0.1 i386-mswin32) gem_plugin (0.2.3) i18n (0.4.2, 0.4.1) linecache (0.43 mswin32) mail (2.2.9, 2.2.7) mime-types (1.16) mongrel (1.1.5 x86-mingw32) mongrel_service (0.4.beta3) mysql (2.8.1 x86-mingw32, 2.7.3 mswin32) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.6) rails (3.0.1) railties (3.0.1, 3.0.0) rake (0.8.7) rdiscount (1.6.5) ruby-debug-base (0.10.3 mswin32) ruby-debug-ide (0.4.5) ruby-odbc (0.99992) sqlite3-ruby (1.3.2 x86-mingw32, 1.3.1 x86-mingw32) thor (0.14.4, 0.14.3) treetop (1.4.8) tzinfo (0.3.23)

database.yml development:   adapter: sqlserver   database: m_development   dsn: M2   mode: odbc   username: user   password: Secret   encoding: utf8

Every time I run rails generate scaffold Something, I get an error like this one:

$ rails generate scaffold Test       invoke active_record c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the sqlserver adapter: `gem install activerecord-sqlserver-adapter` (no such file to load -- active_record/connection_adapters/sqlserver_adapter) (RuntimeError)         from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'         from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'

If I look in connection_specification.rb around line 71 I see this:

        begin             require "active_record/connection_adapters/#{spec[:adapter]}_adapter"           rescue LoadError             raise "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{$!})"           end

Some debugging tells me that spec[:adapter] contains the "sqlserver" from the database.yml file. But I have, as you can see from the list of installed gems, already installed the SQLServer Adapter, so why can't it be found?

I have tried to run gem install activerecord-sqlserver-adapter more than once, but that doesn't help, and I can find the gem in WindowsExplorer in "C:\Ruby\lib\ruby\gems\1.8\gems\activerecord-sqlserver-adapter-3.0.5\lib\active_record\connection_adapters"

Is it a problem with GEM_HOME or do I use a wrong version of rails?

Thanks

Magnus

I had similar problems on windows server 2003 try the steps in the link below and it should work ( i use mongrel as my webserver)

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/90bac21d2f5d2616/908fbcaed47c5259#908fbcaed47c5259

Fredrik TiC Jansson wrote in post #961665:

I had similar problems on windows server 2003 try the steps in the link below and it should work ( i use mongrel as my webserver)

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/90bac21d2f5d2616/908fbcaed47c5259#908fbcaed47c5259

It seems to be working.

Thanks for the help, I really appreciate it.

Magnus

I'm still having some problems with SQLserver adapter.

I have a model called Post, and I try to select a single post object with Post.first in the rails console. But I get an error.

$ rails console Loading development environment (Rails 3.0.2) irb(main):001:0> fp = Post.first ActiveRecord::StatementInvalid: ODBC::Error: 37000 (102) [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '1'.: SELECT [posts].* FROM [posts] LIMIT 1         from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-3.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `log'         from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.0.5/lib/active_record/connection_adapters/sqlserver/database_statements.rb:249:in `raw_select '

The correct SQL should be something like this "SELECT TOP (1) [posts].* FROM [posts]" The LIMIT-part is mySQL-sql if I remember correctly, but where can I change to use some real SQL?

I have downgraded to rails 3.0.1 and the problem has disappered. I wonder why. :slight_smile:

Magnus D. <lists@...> writes:

I have downgraded to rails 3.0.1 and the problem has disappered. I wonder why. :slight_smile:

Seams like the adapter still doesn't support Arel 2.0.