rubyruby-on-rails-3azure-sql-databasetiny-tds

Connecting to SQL-Azure in rails using tiny_TDS: [BUG] Segmentation fault


We're trying to get rails to talk to a sqlserver db on Azure, we install freeTDS with openssl and libiconv:

./configure --prefix=/usr/local --with-libiconv-prefix=DIR --with-openssl=DIR
make
make install

We then add tiny_TDS and activerecord-sqlserver-adapter to the gemfile:

gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'

$ bundle install

Configure the database:

development:  
  adapter: sqlserver
  host: xxxxxxx.database.windows.net
  mode: DBLIB
  port: 1433
  database: xxxxx
  username: xxxxxxxx
  password: x
  azure: true

Run the server:

$ rails s

Everything works great up until this point, but as soon as you visit the site ruby crashes.

steven@jenny:~/irr$ rails server -p 3001
=> Booting WEBrick
=> Rails 3.0.4 application starting in development on http://0.0.0.0:3001
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-24 15:37:00] INFO  WEBrick 1.3.1
[2012-07-24 15:37:00] INFO  ruby 1.9.2 (2012-02-14) [x86_64-linux]
[2012-07-24 15:37:00] INFO  WEBrick::HTTPServer#start: pid=7586 port=3001
/home/steven/.rvm/gems/ruby-1.9.2-p318/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68: [BUG] Segmentation fault
ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-linux]

-- control frame ----------
c:0048 p:---- s:0232 b:0232 l:000231 d:000231 CFUNC  :connect
c:0047 p:0429 s:0228 b:0228 l:000227 d:000227 METHOD /home/steven/.rvm/gems/ruby-1.9.2-p318/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68

We've tried several versions of ruby: 1.9.2-p318, 1.9.2-p320, 1.9.3-p125. Same error with all of them.

This is on ubuntu 11.10 using rvm and FreeTDS-0.9.1.

Any Ideas on a workaround?

Have I made an error somewhere along the way?

Edit

Output from IRB:

require 'tiny_tds'
client = TinyTds::Client.new(:username =>'XXXXX@XXXXXXX.database.windows.net', :password => 'XXXXXXX', :host => 'XXXXXX.database.windows.net',  :mode => 'DBLIB', :azure => 'true')
SystemStackError: stack level too deep from /home/martinr/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!!

It seems to be a bug with ruby itself:

/home/martinr/.rvm/gems/ruby-1.9.2-p320/gems/tiny_tds-0.5.1/lib/tiny_tds/client.rb:68: [BUG] Segmentation fault (core dumped)

Solution

  • The error seems to be caused by having a username username@servername

    When you remove the @severname part, ruby no longer crashes