Reputation: 485
Trying to connect to Sql Server from Rails. Not working so far.
I was advised to add this line to the Gemfile
(as a fix to a known bug):
gem 'activerecord-sqlserver-adapter', git: 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git'
Since I have a proxy, I didn't do this but had to perform a workaround: download the zip from that link, then unzip it in the rails project in a directory called AR, in CMD I migrated inside AR and ran
gem build activerecord-sqlserver-adapter.gemspec
After this, a gem is created, called: activerecord-sqlserver-adapter-3.2.12.gem
so I typed
gem install activerecord-sqlserver-adapter-3.2.12.gem.
Success. At this point, no reference to any adaptors in the gemfile. rails s
is successful: booting WEBrick, Rails 4.1.1 starting in development on...
.
However, when I open localhost:3000
I see a
ActiveRecord::Connection not Established error
I should mention that the database.yml file (from config) contains:
development:
adapter: activerecord-sqlserver-adapter
mode: odbc
dsn: odbc_new
host: localhost
database: cms
pool: 5
username: gst1
password: pwd1234!@
And the cms database exists, I added that user and password to it. What is missing here? Why the connection error? Oh, I also opened Control Panel (Windows 7) - Administrative tools - set up data sources (ODBC) - and added an 'odbc_new' entry with Sql Server authentication, added the user and password there, default db: cms and ran a connectivity test before completion: success.
I don't understand though why or if I really need to create and add this odbc data source there, if I specify the user and password in the database.yml file. Can you help solve this please? Many Thanks in advance.
UPDATE:
I just added adapter: sql server
to my database.yml
. I still get the same error though. Do I have to do something to validate the change in the database.yml
file apart from saving it?
Should I add something to the Gemfile
also? Do I need to add the local adaptor (called activerecord-sqlserver-adapter-3.2.12.gem
) also in my gemfile
(taken from a local drive - instead of rubygems.org
)? I feel the error could be connected to that.
Not sure if I need to do sth like this in the gem file
gem 'activerecord-sqlserver-adapter-3.2.12.gem', :path => 'C:\Site\simple_cms\AR'
but if I do, running
C:\Sites\simple_cms>bundle install
gives an error afterwards:
Fetching gem metadata from https://rubygems.org/...........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Could not find gem 'activerecord-sqlserver-adapter-3.2.12.gem (>= 0)
x86-mingw32' in source at C:/Sites/simple_cms/AR.
Source does not contain any versions of
'activerecord-sqlserver-adapter-3.2.12.gem (>= 0) x86-mingw32'`
UPDATE- I also tried to specify the version number like this: `gem 'activerecord-sqlserver-adapter', '3.2.12', :path => 'C:\Site\simple_cms\AR' but again an error:
`C:\Users\acm>cd C:\Sites\simple_cms
C:\Sites\simple_cms>rails s
←[31mBundler could not find compatible versions for gem "activerecord":
In snapshot (Gemfile.lock):
activerecord (4.1.1)
In Gemfile:
activerecord-sqlserver-adapter (= 3.2.12) x86-mingw32 depends on
activerecord (= 4) x86-mingw32
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
←[0m
Now, After I ran a bundle update
, another error:
C:\Sites\simple_cms>bundle update
Fetching gem metadata from https://rubygems.org/...........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
activerecord-sqlserver-adapter (= 3.2.12) x86-mingw32 depends on
activerecord (= 4) x86-mingw32 depends on
activesupport (= 4.0.0) x86-mingw32
rails (= 4.1.1) x86-mingw32 depends on
activesupport (4.1.1)
Upvotes: 0
Views: 1310
Reputation: 4551
Checking out this question bundler seems to be picky about the gems it tries to install from a local :path
. Could you try specifying the version number as
gem 'activerecord-sqlserver-adapter', '3.2.12', :path => 'C:\Site\simple_cms\AR'
I do not think your load path will be up to snuff if bundler
thinks it cannot resolve this gem.
Upvotes: 1