Sql Server Adapter for Rails

Unable to connect sql server using ruby on rails

You installed version 2.3.8 of the activerecord-sqlserver-adapter gem that is almost 8 years old and tried to run it with the latest version of Ruby on Rails. Obviously, both versions are not compatible.

Furthermore, looking at the gem's Rubygem page - there is no version supporting Ruby on Rails 5.2 yet.

My advice is to downgrade your application to 5.1 and postpone updating to Rails 5.2 until all gems your application is depending on are supporting 5.2

You might want to subscript to these issues on GitHub for further updates:

  • https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/636
  • https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/647

How to connect to MS SQL in Rails

Got an answer to this here: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/250

'You can try connecting to your DB like so, this works for us on that branch on Rails 4:'

class LegacyTable < ActiveRecord::Base
establish_connection({
:adapter => "sqlserver",
:host => "host",
:username => "user",
:password => "pass",
:database => "dbname"
})

This solved my issue. Hope it helps someone in the future.

SQL Server Adapter for Rails

I just ran the exact command line you did, and the gem installs fine.

Questions:

  1. Are you running Vista?

    • If so, make sure you run your command prompt with administrative access, so it can write to the gems folder
  2. Do you have the latest version of gems?

    • Run gem --version to find out what you have, if it's not 1.2.0, then run gem update --system to get the latest

Connect rails with sql server 2012 remotly

Use the following gems for connecting sql server :

gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'

And the database.yml should look like this:

development:
  mode: dblib
  adapter: sqlserver
  host: <host or ip>
  database: <DBNAME>
  username: uname
  password: password
  timeout: 0

you can check gems documentation for further usage.



Related Topics



Leave a reply



Submit