Setting up Rails for SQL Server

December 2nd, 2005

First of all you need to grab the ADO file (as described here).

Then set up your config/database.yml to look something like:

development:  adapter: sqlserver  server: server_name  database: database_name  host: DBI:ADO:Provider=SQLOLEDB;Data Source=server_name;Initial Catalog=database_name;User Id=user_name;Password=your_pw_here;  username: user_name  password: your_pw_here

Some of these values are repeated as it helps the various parts pull out the information they need without the whole connection string getting in the way.

Speaking of which, we need to alter your rakefile:

In lines 160 and 161 change

abcs[RAILS_ENV]["host"]

to

abcs[RAILS_ENV]["server"]

In line 139 change

abcs["test"]["host"]

to

abcs["test"]["server"]

The following are patches that I will submit to dev.rubyonrails.org when I figure out what I need to do …

In /ruby/lib/ruby/gems/1.8/gems/actionwebservice-version/lib/action_web_service/casting.rb

Look for line 53 – above

elsif signature_type.structured?

insert the following lines:

elsif value  true || value  false  cast_base_type(value, :bool)

This is because ActiveWebService does not know how to deal with booleans (which MySQL does not use, but SQL Server does, with its BIT fields).

In /ruby/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/connection_adapters/sqlserver_adapter.db

Look for line 61 – above

when /bit/i then :boolean 

insert the following lines:

when /uniqueidentifier/i then :string 

This is because ActiveWebService does not know how to deal with uniqueidentifier fields (which MySQL does not have). Luckily SQL Server is quite happy to accept strings for uniqueidentifiers and converts them implicitly – so we just tell the SQL Server Adapter to use strings whenever it comes across a uniqueidentifier.

Comments are closed.