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:
Are you running Vista?
- If so, make sure you run your command prompt with administrative access, so it can write to the gems folder
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 rungem update --system
to get the latest
- Run
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
Using a SQL Server for Application Logging. Pros/Cons
How to Get the Last Month Data and Month to Date Data
Presto Check If Null and Return Default (Nvl Analog)
Update Multiple Records in Sql
Rodbc and Microsoft SQL Server: Truncating Long Character Strings
Postgresql Query to Select Data from Last Week
Insert-Output Including Column from Other Table
How to Use Left & Right Functions in SQL to Get Last 3 Characters
How to Use a Trim Function in SQL Server