2

Can you point me to any good resources that show how to connect Sql Server to Rails app (Windows 7)?

I have done the following so far: rails new simple_cms –d sqlserver

gem install bundle

rails s

after the last command, this error is thrown:

C:\Sites\s_cms>rails s
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `add_order!' for class `Class' (Name
Error)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:14:in `singletonclass'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:12:in `inc
luded'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:145:in `in
clude'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:145:in `<t
op (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:3:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:3:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/activerecord-sqlserver-adapter.rb:1:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/activerecord-sqlserver-adapter.rb:1:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler.rb:132:in `require'
        from C:/Sites/s_cms/config/application.rb:7:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `block in server'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

PS: If I use sqlite as a database system, I am able to successfully start the webserver (no error). This probably means there's nothing wrong with my rails installation. I am guessing I might need to add sth to database.yml or write the database user and password somewhere. But how come this is not required with sqlite3? I also found this resource but not sure if still applicable (it refers to rails 2.0, whereas I use rails 4.1.1) http://rubyrailsandwindows.blogspot.de/2008/03/rails-2-and-sql-server-2008-on-windows_24.html - and some of the things there I tried but don't apply. Thanks in advance.

Later edit: I also tried rails s after editing the database.yml (from the config folder) to contain:

development:
  adapter: sqlserver
  encoding: unicode
  database: cms
  pool: 5
  username: guest1
  password: pwd1234%^&^
test:
  adapter: sqlserver
  encoding: unicode
  database: cms
  pool: 5
  username: guest1
  password: pwd1234%^&^
production:
  adapter: sqlserver
  encoding: unicode
  database: cms
  pool: 5
  username: guest1
  password: pwd1234%^&^

(of course, I also created previously a db called cms, and added a user called guest1 with the specified password, then made sure teh credentials worked to connect to the db by mimic-ing network connection from my local Sql Server itself)

After this new action I get a similar error as above:

C:\Sites\simple_cms>rails s
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `add_order!' for class `Class' (Name Error)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
        ...............

1 Answer 1

2

This is a known bug with activerecord-sqlserver-adapter. It's being worked on but any fix has not yet been merged into a milestone.

It appears the workaround just now is to change your Gemfile to have:

gem 'activerecord-sqlserver-adapter', git: 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git'

Details of the issue are here and the efforts to fix it are here.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you so much, Graeme. I edited the gemfile as you recommended, then ran rails s once again. It prompted me to do a bundle install - after I try to run that, however, I get: Fetching https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git fatal: unable to access 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapt er.git/': Failed connect to github.com:443; No error Retrying git clone "https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.gi t" "C:/Ruby193/lib/ruby/gems/1.9.1/cache/bundler/git/activerecord-sqlserver-adapter-a19f0 dc7902.....
Could this be again because of the proxy? I thought I was rid of that after I set the HTTP_PROXY environment variable as suggested here: stackoverflow.com/questions/23607571/set-proxy-for-rubygems . I don't know how to force the bundle install to run with a proxy (syntax??) or if that is even the problem. Strangely, I am able to connect to github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git by typing this address in the browser, hence why I think it could be a proxy thing again.
Could well be your proxy. That fork does have a valid .gemspec so it should work. Given you can access the repositary you might need to bring it down as a zip (unless you can git clone it) and build it locally. Put it somewhere then run gem build activerecord-sqlserver-adapter.gemspec in that directory followed by gem install <name of gem that was just built>
I went to this page (github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter) , downloaded the zip file (activerecord-sqlserver-adapter-master.zip), then went to the root of our rails app , copied the unzipped archive there, ran the gem build activerecord-sqlserver-adapter.gemspec in that directory (called activerecord-sqlserver-adapter-master) and the following error comes up: C:\Sites\activerecord-sqlserver-adapter-master>gem build activerecord-sqlserver-adapter.gemspec ERROR: Gemspec file not found: activerecord-sqlserver-adapter.gemspec Thanks for all your patience...
Are you definately in the directory with the .gemspec file? I just tried it on Windows and it worked - when it unzipped the file it was in a nested directory C:\activerecord-sqlserver-adapter-master\activerecord-sqlserver-adapter-master. However I just went to the directory with the gemspec and typed gem build a<TAB>, using <TAB> to let it autocomplete the filename and be sure it was correct.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.