Daniel Berger
Posts: 1383
Nickname: djberg96
Registered: Sep, 2004
|
Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
|
|
|
|
Trick or Sql Server!
|
Posted: Oct 31, 2006 3:13 PM
|
|
|
This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
|
Original Post: Trick or Sql Server!
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...
|
|
Um, I'll take 'trick' next time.
I just spent seven hours today figuring out how to configure, build and install all of the components needed to talk to a Sql Server database from a Unix box.
I gained 23 gray hairs, broke my right pinky smashing a keyboard and nearly lost an eye to a stray flying pencil in the process, so pay attention! I'm writing this for you. Because I love you.
The most valuable resource was by far this wiki page. That got me about 90% of the way there. Note the extra comments at the bottom. They were very valuable (though slightly off in a couple instances which caused me some grief).
Below is the process you need. Adjust all instances of "/usr/local" as appropriate.
* Add this to your /etc/profile:
export ODBCINI=/usr/local/etc/odbc.ini export ODBCSYSINI=/usr/local/etc
* Install unixODBC. Do the standard configure, make, make install.
Skip this step on Solaris.
* Install FreeTDS. If you're building from scratch build like so:
./configure --with-unixodbc=/usr/local --with-tdsver=8.0 --enable-msdblib
If you're on Solaris, just install the FreeTDS package from blastave. It comes with unixODBC and the msdblib support builtin.
If you install using an rpm/apt-get/whatever, make sure that you have msdblib support builtin. You can tell by running 'tsql -C'. If not, you may have problems.
* Setup your freetds.conf file. It should look something like this:
[some_symbolic_name] host = your.host.com
* Attempt to connect via tsql by running 'tsql -S some_symbolic_name -U login -P passwd'. If you get a prompt, you're good to go. If not, something went wrong.
* Create your database definition files. This is the ODBC stuff. Your /usr/local/etc/odbc.ini entry should look something like this:
[iamspsql01] Driver = FreeTDS Description = ODBC connection via FreeTDS Trace = No Servername = some_symbolic_name Database = YourDatabase
Your /usr/local/etc/odbcinst.ini should look like this:
[FreeTDS] Description = TDS driver (Sybase/MS SQL) Driver = /usr/local/lib/libtdsodbc.so Setup = /usr/local/lib/libtdsS.so CPTimeout = CPReuse = FileUsage = 1
* Attempt to connect via isql by running 'isql some_symbolic_name user passwd'. If it works you're good to go. If not, something is wrong.
Making sure the freetds.conf, odbc.ini and odbcinst.ini files were all configured properly was the hardest part for me.
= Ruby stuff =
* Install the Ruby ODBC driver. You can get it here. I recommend building with 'ruby extconf.rb --with-dlopen; make; make install'.
* Attempt to connect using DBI. Your connection will look something like this:
DBI.connect("dbi:ODBC:some_symbolic_name", user, pass)
* Attempt to connect using Rails. Your connection will look something like this:
ActiveRecord::Base.establish_connection( :username => "user", :password => "XXXX", :adapter => "sqlserver", :database => "YourDatabase", :mode => "odbc", :dsn => "some_symbolic_name" )
Read: Trick or Sql Server!
|
|