Setting Up Rails to Work with SQLserver

Setting up Rails to work with sqlserver

I ran into the same problem yesterday. Apparently 'deprecated' is a gem, so you want to run "gem install deprecated" to grab and install the latest version. Good luck.

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

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......

Connect Sql server in Ruby on rails

I haven't done it on Windows, but if it's anything like connecting to postgresql on a mac you have to:

  1. Have sql-server running locally (http://msdn.microsoft.com/en-us/library/ms143219.aspx ?)
  2. Add a gem to your gemfile that will allow Rails to talk to
    sql-server, probably this:
    https://github.com/rails-sqlserver/activerecord-sqlserver-adapter |
    gem 'activerecord-sqlserver-adapter', '~> 3.1.0'
  3. Update your database.yml file for sql server, example here: Setting up Rails to work with sqlserver (plus it's also the answer)
  4. Then you would just create the db and migrate it. On a mac it's like
    this rake db:create && rake db:migrate

Ruby on Rails and Microsoft SQL server

We're using this adapter in our project. Yes, you can use the 'normal way' to map you're models. Although we're only using it to read from the database I'm pretty sure the writes work the usual way as well.

If devise works strongly depends on the presence of the columns that devise expects.

Getting a MS Sql Server to run under OSX will be tricky enough. I'm not sure there are any trial licenses.

Using existing SQL Server database with Ruby on Rails

You're in luck, friend. My first Rails project (7 years ago) was against a horribly set up SQL Server database.

Per the above, you need to set up your database.yml appropriately. But for an existing database, obviously it is unlikely that the table and column names conform to the Rails conventions. The good news is that you can override all of those defaults. Here is a non-exhaustive list of those directives:

In a model descended from AR::Base,

set_table_name 'actual_table_name'

set_primary_key 'actual_primary_key_name'

On the various association directives (has_one, has_many, belongs_to), there are :foreign_key keys that let you specify the name of the foreign keys.

Now, one of the things that MS SQL Server allows you to do which is TERRIBLE is that you can embed spaces into your column names. Fear not, you can still refer to these columns by name using write_attribute("badly named column") and read_attribute("badly named column"). You may also refer to them in various directives like so:

validates_length_of "Fax Number", :maximum => 17, :allow_nil => true

Finally, you may refer to the implied methods these devilishly named columns generate like so:

self.send('Fax Number=', new_fax_number)

Obviously, you can't refer to them as symbols, since spaces are disallowed in Ruby symbols.

Good luck, and next time I hope that you get to work with a real RDBMS, like Informix :).

How can I use an existing MS SQL database into new Ruby on Rails project?

We run a kind of legacy database with rails at work. Some of the stuff was added through SQL, other things were added via migrations etc. Basically, the answer to your question is yes, and you can even run migrations etc for subsequent database maintenance. But to get started, you just need to tell rails where to look for the table when given a model.

From Active Record Basics: 4 Overriding the Naming Conventions:

What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions.

You can use the ActiveRecord::Base.table_name= method to specify the table name that should be used:

class Product < ActiveRecord::Base
self.table_name = "my_products"
end

...

It's also possible to override the column that should be used as the table's primary key using the ActiveRecord::Base.primary_key= method:

class Product < ActiveRecord::Base
self.primary_key = "product_id"
end

Connecting to an MSSQL database from a Ruby on Rails application running on Ubuntu

This Stackoverflow question might help: Rails & MSSQL 2008 - Will We Hit Barriers?

Basically you will need to install a MSSQL database adapter (rather than MySQL or Postgres that most tutorials step you through), and configure your database.yml appropriately:

http://rorblog.techcfl.com/2008/04/14/ruby-on-rails-connection-to-sql-server/

http://the-banana-peel.saltybanana.com/2008/06/connecto-to-microsoft-sql-server-from.html

http://wiki.rubyonrails.org/database-support/ms-sql (Although the rails wiki looks down at time of writing)

P.S. I am assuming the MSSQL server will be running on a separate Microsoft server someplace.



Related Topics



Leave a reply



Submit