Archive for the ‘Rails’ Category

Using rails-sqlserver-2000-2005-adapter on Windows

This is a different approach to my previous post Using SQL Server in Rails 2

Now I am using Rails 2.2.2 on Windows and the Rails SQL Server 2000-2005 adapter. Additionally I am using ODBC, because ADO support seems to be deprecated.

The installation is straightforward as explained on the adapter github page:

Since we are using ODBC it is necessary to configure the data source using the ODBC Data Source Administrator in Windows Administrative Tools. In my case I used a System DSN.

The config\database.yml should look like this:

Where your_database_dsn is the System Data Source name that you defined in the ODBC Data Source Administrator.

Using SQL Server in Rails 2

These are the steps to access a SQL Server database from a Rails 2.0 application running on Windows.

The SQL Server adapter is not incuded by default in Rails 2. It is necessary to download and install it using the following command.

gem install activerecord-sqlserver-adapter
--source=http://gems.rubyonrails.org

Download the latest version of ruby-dbi from

http://rubyforge.org/projects/ruby-dbi/

and then extract the file from ruby-dbi\lib\dbd\ADO.rb

to C:\ruby\lib\ruby\site_ruby\1.8\DBD\ADO\ADO.rb.

Warning, the folder ADO does not exist, so you have to create it in advance.

It is not possible to preconfigure rails for SQL Server using the --database option, just create your application as usual and then modify config\database.yml in your application folder as follows:

development:
adapter: sqlserver
database: your_database_name
host: your_sqlserver_host
username: your_sqlserver_user
password: your_sqlserver_password

Run rake db:migrate to check your installation. If everything is fine you should not receive any error message.