Connecting to SQL Server from Mac via Actual Technologies's ODBC driver
Anyone out there successfully connect to SQL Server from 64bit Mac OS X 10.6 (Snow Leopard) using Actual Technologies's ODBC driver? I'm not interested in using the iODBC Unix driver.
For Ruby 1.8.7 I have:
- dbi (0.4.5)
- dbd-odbc (0.2.5)
- ruby-odbc (0.99992)
Here's my simple Ruby script:
require 'rubygems' require 'dbi' db = DBI.connect('DBI:ODBC:MyDSN', 'user', 'password') begin result = db.execute('SELECT name FROM sys.databases') while row = result.fetch do puts row.to_s end ensure db.di开发者_如何学JAVAsconnect if db end
I've also tried this using ActiveRecord:
- activerecord (1.15.6)
- activerecord-sqlserver-adapter (3.0.5)
Script:
require 'rubygems' gem 'activerecord' require 'active_record' require 'logger'ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection( :adapter => 'sqlserver', :mode => 'odbc', :dsn => 'MyDSN', :username => 'user', :password => 'password' )
result = ActiveRecord::Base.connection.execute 'SELECT name FROM sys.databases'
while r = result.fetch_row puts r end
However, on fetch, both the DBI and ActiveRecord examples error with a Segmentation fault:
/opt/local/lib/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbd/odbc/statement.rb:43: [BUG] Segmentation fault ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]In Ruby 1.9.2 there's more error information:
/Users/ejstembler/.rvm/gems/ruby-1.9.2-p0/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:41: [BUG] Segmentation fault ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10]-- control frame ---------- c:0006 p:---- s:0022 b:0022 l:000021 d:000021 CFUNC :fetch c:0005 p:0014 s:0019 b:0018 l:000017 d:000017 METHOD /Users/ejstembler/.rvm/gems/ruby-1.9.2-p0/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:41 c:0004 p:0139 s:0014 b:0014 l:000013 d:000013 METHOD /Users/ejstembler/.rvm/gems/ruby-1.9.2-p0/gems/dbi-0.4.5/lib/dbi/handles/statement.rb:220 c:0003 p:0102 s:0009 b:0009 l:001588 d:0001e0 EVAL ss_dbi.rb:7 c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:001588 d:001588 TOP
-- Ruby level backtrace information ---------------------------------------- ss_dbi.rb:7:in
<main>' /Users/ejstembler/.rvm/gems/ruby-1.9.2-p0/gems/dbi-0.4.5/lib/dbi/handles/statement.rb:220:in
fetch' /Users/ejstembler/.rvm/gems/ruby-1.9.2-p0/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:41:infetch' /Users/ejstembler/.rvm/gems/ruby-1.9.2-p0/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:41:in
fetch'-- C level backtrace information -------------------------------------------
I'm not familiar with reading this type of error dump, however if I were to guess I would say that fetch is the last thing being called for it calls out to a C function (CFUNC). I'm not sure if the C function is part of a gem, the Ruby library, or the ODBC driver itself.
Any ideas?
Have you looked at the OpenLink Rails ODBC Adapter and ODBC Driver for SQL Server on Mac OS X which have specific enhancements for working with Ruby on Rails and have been tested on Mac OS X ?
Did you ever figure this out?
I'm using Ruby-ODBC and ActiveRecord on Windows to query a custom driver:
require "sinatra/activerecord"
require "odbc"
I wrote the following:
maxwell = ODBC.connect("Maxwell")
stmt = maxwell.run query
The DSN ("Maxwell") was configured globally (outside my Ruby app) and I didn't need to specify the driver, since this already was set in odbc.ini.
精彩评论