Skip to content

Instantly share code, notes, and snippets.

@hgmnz
Created March 14, 2009 17:39
Show Gist options
  • Save hgmnz/79129 to your computer and use it in GitHub Desktop.
Save hgmnz/79129 to your computer and use it in GitHub Desktop.
(Using Fedora Core 9)
http://wiki.rubyonrails.org/database-support/ms-sql
sudo yum install unixODBC.x86_64 unixODBC-devel.x86_64
sudo yum install freetds.x86_64 freetds-devel.x86_64
sudo gem install dbd-odbc
sudo gem install dbi
sudo gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org
In /etc/freetds.conf
[server_def]
host = server_ip_address
port = 1433
tds version = 8.0
client charset = UTF-8
In /etc/odbc.ini
[server_def]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = server_def
Database = server_db
In /etc/odbcinst.ini
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib64/libtdsodbc.so
Setup = /usr/lib64/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
TDS Should be set up fine:
tsql -S server -U user -P password
In production.log, I get this error:
DBI::InterfaceError (Unable to load driver 'ODBC' (underlying error: uninitialized constant DBI::DBD::ODBC))
Solution was to install ruby-odbc:
RubyODBC:
wget http://ch-werner.de/rubyodbc/ruby-odbc-0.9996.tar.gz
tar -xvzpf ruby-odbc-0.9996.tar.gz
cd ruby-odbc-0.9996
ruby extconf.rb
make
sudo make install
But now, you'll get this error:
DBI::DatabaseError (IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified)
/usr/lib64/ruby/gems/1.8/gems/dbd-odbc-0.2.4/lib/dbd/odbc/driver.rb:36:in `connect'
/usr/lib64/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi/handles/driver.rb:33:in `connect'
/usr/lib64/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:142:in `connect'
/usr/lib64/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-1.0.0.9250/lib/active_record/connection_adapters/sqlserver_adapter.rb
:47:in `sqlserver_connection'
This happens to be a problem with the data source. To test this directly:
isql -v datasource username password
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
I've also tried symlinking both config files to /usr/local/etc:
sudo ln -s /etc/odbc.ini /usr/local/etc/odbc.ini
sudo ln -s /etc/odbcinst.ini /usr/local/etc/odbcinst.ini
Might be helpful to use dltest => The Driver=xxx entry points to a shared object which does not export the necessary ODBC API functions (you can test this with dltest included with unixODBC)
@hgmnz
Copy link
Author

hgmnz commented Jan 28, 2013

@will because I don't know if you get notified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment