views:

1046

answers:

6

I'm trying to connect to SQL Server on Ubuntu 9.04 using Ruby. I translated and followed all the steps outlined in getting OSX talking to SQL Server from here:

http://toolmantim.com/articles/getting_rails_talking_to_sqlserver_on_osx_via_odbc

Everything is working on the FreeTDS and unixODBC end. I can see and query the database using tsql.

When I try to access the database from Ruby using IRB I get the following error:

DBI::DatabaseError : INTERN (0) [RubyODBC] Cannot allocate SQLHENV

Has anyone run into this and what can I do to solve this?

A: 

Go fig that I actually got this working after submitting my question. What I ended up doing was uninstall libdbd-odbc-ruby and libdbi-ruby and then reinstalling them by installing libdbi-ruby first and then installing libdbd-odbc-ruby. I guess when I installed them before, something must of messed up.

rip747
+4  A: 

I started getting this error when I upgraded to Ubuntu 9.10 (Karmic Koala). Your tip regarding installation order of the Ubuntu packages didn't work for me.

It seems the fix was to manually compile ruby-odbc.

wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz
tar xzvf ruby-odbc-0.9997.tar.gz
cd ruby-odbc-0.9997
ruby extconf.rb --with-dlopen
make
sudo make install
Tim Morgan
Thank you, that finally solves the issues I've been having. Must be a Karmic-specific bug.
Adam Lassek
This solved my problem also... GOD!! Thanks!!
mickey
I wanted to add that all seems to be working when using Ruby Enterprise Edition. Regular ol' gem install stuff works as of REE 1.8.7-2010.01
Tim Morgan
A: 

BTW, following the instructions to recompile Ruby-ODBC on Ubuntu 9.10 (Karmic) required installation of either the libiodbc2-dev or the unixodbc-dev package. When using libiodbc2-dev, I got segmentation faults when my Ruby program tried:

connection.select_all('select top 15 * from log_device_healths')

..but no problem when using unixodbc-dev instead.

Leslie Viljoen
A: 

Tim Morgan's solution didn't work for me. However I was able to get things working by installing an older version of libodbc-ruby (0.9995) from here:

http://mirrors.kernel.org/ubuntu/pool/universe/libo/libodbc-ruby/libodbc-ruby1.8_0.9995-1_i386.deb

Additional details are available from Carsten Gehling's blog:

http://gehling.dk/2010/02/the-woes-of-libodbc-ruby1-8-and-debian-ubuntu/

Be careful though -- Ubuntu's Update Manager will happily "upgrade" this version of libodbc-ruby to the broken 0.9997-2. I accidentally overwrote the older version this way only to end up back here, trying to figure out how I fixed it last time.

Matt Zukowski
A: 

Well, it seems my other answer stopped working for me. This thread helped me to solve the issue in another way, and I wanted to share it here.

sudo gem uninstall ruby-odbc
sudo rm /usr/local/lib/site_ruby/1.8/x86_64-linux/odbc.so
cd /tmp
wget http://mirrors.kernel.org/ubuntu/pool/universe/libo/libodbc-ruby/libodbc-ruby1.8_0.9995-1_amd64.deb
sudo dpkg -i libodbc-ruby1.8_0.9995-1_amd64.deb

If you're not on a 64-bit platform, you'll need to download a different Debian package.

Basically, what solves the problem is installing version 0.9995 of the ruby-odbc Ubuntu package.

Tim Morgan
+2  A: 

System

Ubuntu 9.10 64 bit

I had to specify the odbc directory in the rubyodbc install

wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz
tar xzvf ruby-odbc-0.9997.tar.gz
cd ruby-odbc-0.9997
ruby extconf.rb --with-odbc-dir=/usr/lib/odbc --disable-dlopen
make
sudo make install
JBK