How may i connect ruby on rails with sql server on windows

12,261

Sorry to disappoint you, but there are no easy solutions for using Rails on a Windows platform. It was not designed to run on Windows and I don't think I would recommend Windows as a platform for a Rails app. Not to say it hasn't been done, but in my experience it would be far easier to setup and run on a Linux platform as it was designed to do.

There is support for MS SQL server and Rails and you can checkout this project for more information.

My recommendation is to learn more about Rails and setting it up the environment, because a red flag to me is that you want to deploy a Rails app and yet do not know how to set it for production. This should be Rails 101 knowledge. Production is just another environment for Rails, there are things you need to be aware of when running a Rails app in production and this information can be found on easily rubyonrails.org.

Put some more time into learning Rails and perhaps setup a Linux virtual machine, deploy your Rails app, and experiment. Once you learn how to deploy Rails on a Linux platform them perhaps it may be a little easier to understand how to go about doing it on Windows.

please refer :-- https://github.com/rails-sqlserver/activerecord-sqlserver-adapter

Or else you can try with this

What is left is to learn is how to use database engine that is probably of the most interest for developers who work on Windows – Microsoft's SQL Server. If you do not have MS SQL Server installed go ahead and download MS SQL Server Express installer from Microsoft's site. I will use version 2014 in this book. Let's first create database that we will use in our Rails application:

osql -b -S localhost -U -P -Q "CREATE DATABASE RwinBookDevel COLLATE SQL_Latin1_General_CP1_CS_AS"

Newest rails adapter for MS SQL Server uses tiny_tds library to connect to MS SQL server and its usage is almost straigtforward. First thing we have to do is to add following two lines to Gemfile:

gem 'tiny_tds'

gem 'activerecord-sqlserver-adapter'

And run bundle install.

With all prerequisites met we can now configure our Ruby on Rails application to use SQL Server. Connection options are displayed below:

development:

adapter: sqlserver
mode: dblib
host: localhost
port: 1433
username: <your_db_user_name>
password: <your_db_password>
database: ABC

Hope this will help you......

Share:
12,261
Mahesh Sharma
Author by

Mahesh Sharma

Updated on June 28, 2022

Comments

  • Mahesh Sharma
    Mahesh Sharma almost 2 years

    Want to use sql server as a database instead of mysql in Windows.What configuration i need to change in database.yml file and what all gems are needed for installation.Please help.