# Ubuntu 9.10 / Sql Server 2005 / ODBC connectivity problem

**URL:** <https://www.ruby-forum.com/t/ubuntu-9-10-sql-server-2005-odbc-connectivity-problem/180144>\
**Category:** Rails\
**Created:** [December 13, 2009, 9:28am UTC](https://www.ruby-forum.com/t/ubuntu-9-10-sql-server-2005-odbc-connectivity-problem/180144 "2009-12-13T09:28:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew106](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b77776/32.png) [@matthew106](https://www.ruby-forum.com/u/matthew106)\
**Post date:** [December 13, 2009, 9:28am UTC](https://www.ruby-forum.com/t/ubuntu-9-10-sql-server-2005-odbc-connectivity-problem/180144/1 "2009-12-13T09:28:28Z")

</div>

Hi,

I’ve followed the instruction at  
[http://wiki.rubyonrails.org/database-support/ms-sql](http://wiki.rubyonrails.org/database-support/ms-sql) in order to get RoR  
talking to Sql Server but having followed the various steps and running  
rake db:create using a DSN-less connection i get the following error:

(in /var/www/DemoApp)  
\*\* Invoke db:create (first\_time)  
\*\* Invoke db:load\_config (first\_time)  
\*\* Invoke rails\_env (first\_time)  
\*\* Execute rails\_env  
\*\* Execute db:load\_config  
\*\* Execute db:create  
rake aborted!  
undefined method `[]' for nil:NilClass /var/lib/gems/1.8/gems/rails-2.3.5/lib/tasks/databases.rake:55:in `create\_database’  
/var/lib/gems/1.8/gems/rails-2.3.5/lib/tasks/databases.rake:31  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in  
`invoke_with_call_chain' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top\_level’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top\_level’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in  
`standard_exception_handling' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top\_level’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard\_exception\_handling’  
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /var/lib/gems/1.8/gems/rake-0.8.7/bin/rake:31 /var/lib/gems/1.8/bin/rake:19:in `load’  
/var/lib/gems/1.8/bin/rake:19

Here are precisely the steps i’ve followed as per the instruction on  
page [http://wiki.rubyonrails.org/database-support/ms-sql:](http://wiki.rubyonrails.org/database-support/ms-sql:)

## For UnixODBC:

wget [http://www.unixodbc.org/unixODBC-2.2.14.tar.gz](http://www.unixodbc.org/unixODBC-2.2.14.tar.gz)  
tar xvfz unixODBC-2.2.14.tar.gz  
./configure  
make  
make install

sudo apt-get install unixodbc-dev

## For FreeTDS:

wget  
ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz  
tar xvfz freetds-stable.tgz  
./configure  
make  
make install

sudo apt-get install freetds-dev

## Ruby ODBC binding:

wget [http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz](http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz)  
ruby extconf.rb  
make  
sudo make install

No errors were thrown by any of the above, drivers etc… created as  
expected and can connect to/query sql server using tsql.

## For gems:

sudo gem install dbd-odbc  
sudo gem install dbi  
sudo gem install activerecord-sqlserver-adapter

## database.yml:

development:  
adapter: sqlserver  
mode: ODBC  
dsn:  
DRIVER=/usr/local/lib/libtdsodbc.so;TDS\_Version=8.0;SERVER=192.168.x.xx;DATABASE=xxxxx;Port=1433;uid=sa;pwd=xxxxxxx;

test:  
adapter: sqlserver  
mode: ODBC  
dsn:  
DRIVER=/usr/local/lib/libtdsodbc.so;TDS\_Version=8.0;SERVER=192.168.x.xx;DATABASE=xxxxx;Port=1433;uid=sa;pwd=xxxxxxx;

production:  
adapter: sqlserver  
mode: ODBC  
dsn:  
DRIVER=/usr/local/lib/libtdsodbc.so;TDS\_Version=8.0;SERVER=192.168.x.xx;DATABASE=xxxxx;Port=1433;uid=sa;pwd=xxxxxxx;

I’ve also tried wrapping the dsn in single quotes as per the instruction  
but no difference. i.e.

dsn: ‘DRIVER=…’

I still get the error: undefined method `[]’ for nil:NilClass

I’ve also tried not building unixODBC and instead using the package  
(i.e. sudo apt-get install unixodbc) but that doesn’t produce a driver  
as described in the wiki page. i.e. it does not produce libtdsodbc.so.  
Similarly I’ve also tried not building freetds and instead installing  
the packages freetds-bin, freetds-common and freetds-dev but again  
nothing.

When i navigate to the site in the browser phusion passenger says the  
following:

```
* Your config/database.yml may not be written correctly. Please

```

check it and fix any errors.  
\* Your database schema may be out of date or nonexistant.  
Please run rake db:migrate to ensure that the database schema is  
up-to-date.  
\* The database server may not be running. Please check whether  
it’s running, and start it if it isn’t.

Error message:  
production database is not configured  
(ActiveRecord::AdapterNotSpecified)  
Exception class:  
ActiveRecord::AdapterNotSpecified

Also… when i type the following in irb:

DBI.connect(“dbi:ODBC:Driver=/usr/local/lib/libtdsodbc.so;TDS\_Version=8.0;Server=192.168.x.xx;Database=xxxxx;Uid=sa;Pwd=xxxxxxx;”)

i get the following error:

DBI::DatabaseError: IM002 (0) [unixODBC][Driver Manager]Data source name  
not found, and no default driver specified  
from  
/var/lib/gems/1.8/gems/dbd-odbc-0.2.5/lib/dbd/odbc/driver.rb:36:in  
`connect' from /var/lib/gems/1.8/gems/dbi-0.4.3/lib/dbi/handles/driver.rb:33:in `connect’  
from /var/lib/gems/1.8/gems/dbi-0.4.3/lib/dbi.rb:148:in  
`connect’  
from (irb):5

Any ideas as this is driving me crazy!

Thanks
