I have shared this before but here is my instructions I use for linux... Some are redhat specific but they should be the same or very similar as long as you have any dev packages needed by the compiled code.
Feel free to cleanup/post this if a wiki page is setup.
** Database setup::
1) Install MS SQL 2005 Developer Edition
DB_DEFINITION_NAME: DSN: MY_CONNECTION
DB_NAME: MY_DB
USERNAME: sa
PASSWORD: mypassword
SQL Server Configuration Manager-> Network Configuration -> Protocols for XXX
Enable the TCP/IP Protocol (to allow remote connections)
** Rails machine setup:
Requires:
ruby, rails, and any gems you want
rails-sqlserver-2000-2005-adapter, dbi and dbd-odbc gems as per the adapter's readme
freetds-0.82
ruby-odbc-0.999 (0.9997 is now available at
http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz)
unixODBC-2.2.12 (2.2.14 is now available at
http://www.unixodbc.org/unixODBC-2.2.14.tar.gz)
** Pre-req: Perhaps uninstall any freetds or unixodbc version to avoid conflicts
** If Redhat:
Check if unixODBC or freetds are installed:
rpm -q -a |grep unix
rpm -q -a |grep free
Uninstall them if installed:
ex: rpm -e freetds-0.64-1.el5.rf
ex: rpm -e unixODBC-2.2.11-7.1
1) Edit Profile
Log in as root
nano /etc/profile
export ODBCINI=/etc/odbc.ini
export ODBCSYSINI=/etc
export FREETDSCONF=/etc/freetds/freetds.conf
2) Create a location for the downloaded and extracted files. I use /usr/local/src
3) Install unixODBC (2.2.12)
cd /usr/local/src
wget
http://www.unixodbc.org/unixODBC-2.2.12.tar.gz
gunzip unixODBC*.tar.gz
tar xvf unixODBC*.tar
cd unixODBC*
./configure -prefix=/usr/local -sysconfdir=/etc -disable-gui
make
make install
4) Install FreeTDS (0.82)
cd /usr/local/src
wget
ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zvxf freetds-stable.tgz
cd freetds*/
./configure --with-odbc=/usr/local/lib
make
make install
# If the make fails due to libarary locations, the configure options which did not work
# for me but were the defaults provided are below:
# ./configure --with-unixodbc=/usr/local
4b) Test FreeTDS
nano /usr/local/etc/freetds.conf
Update text size:
# Added limit of 20 MB - FreeTDS truncates anything
# beyond this without raising an error
text size = 2097152
[MY_CONNECTION]
host = 192.168.5.5
port = 1433
tds version = 7.0
# tds version of 8.0 or higher seems to cause problems on 64 bit linux
tsql -S MY_CONNECTION -U sa -P mypassword
locale is "en_US.ISO-8859-15"
locale charset is "ISO-8859-15"
1> use MY_DB
2> go
1> select * from users (do this for a table that exists in your db)
2> go
id login
1 user1
3 user2 (make sure you get correct output)
1> quit
5) Create DB Definition:
/etc/odbc.ini:
[MY_CONNECTION]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = MY_CONNECTION
Database = MY_DB
/etc/odbcinst.ini:
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
5a) Set the LD_LIBRARY_Path to avoid load errors
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
This addresses the following issues:
- isql in 5b: error while loading shared libraries: libodbc.so.1 (no such file or directory)
- Ruby DBI in 7b : no ODBC driver manager found.
5b) Test DB definition
isql MY_CONNECTION sa mypassword
# isql MY_CONNECTION sa mypassword
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select * users;
SQL> quit
6) Install ruby odbc
cd /usr/local/src
wget
http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz
tar zvxf ruby-odbc-0.9997.tar.gz
tar zvxf ruby-odbc-0.9997
cd ruby-odbc*
ruby extconf.rb
make
make install
(odbc.so /usr/local/lib/ruby/site_ruby/1.8/i686-linux)
7 Install the dbi, dbd-odbc and rails-sqlserver-2000-2005-adapter gems as described in the adapter's readme...
7b) Test DBI connection:
# irb1.8
require 'rubygems'
require 'dbi'
dbh = DBI.connect('dbi:ODBC:MY_CONNECTION', 'sa', 'mypassword')
sth = dbh.execute("select * from users")
sth.finish
8) configure database.yml
development/production/test:
adapter: sqlserver
mode: odbc
dsn: MY_DB
username: sa
password: mypassword
9) Rake the DB