Mac OS Rails => SQL Server

I am about to start developing a Rails on my Mac for a client. The
app is connecting to a legacy system that uses SQL Server. Should I
follow the instructions at
http://wiki.rubyonrails.com/rails/pages/
HowtoConnectToMicrosoftSQLServerFromRailsOnLinux

or, does anyone have Mac OS-specific instructions?

Thanks,

Jamie O-H

Hello,
I think your best option would be to use this odbc driver,
http://www.actualtechnologies.com/. The full version is $29.95 and
they also have a demo you can download and test.

Then setup your database.yml like this:
development:
adapter: sqlserver
mode: odbc
dsn: YOUR_DB_DEFINITION_NAME
username: USERNAME
password: PASSWORD


Joe C.

That would probably be the best thing to do. If you’re adamant about
not paying a dime and don’t mind screwing things up a few times, my G5
dev setup at work involves using FreeTDS and the supplied IODBC layer.
You’ll need to use the SQLServer adapter that Tom W. has been
working on, in ODBC mode. I also can’t get the connection working with
a full DSN, so I have ODBC “short DSNs” set up for each server i need
to connect to.

I’ll post my own notes tomorrow when I’m back at work.

  • james

Thanks James and Joe. I am just starting down the Darwin Ports path
of installing this stuff, but may divert over to the actual
technologies driver and test it out. I’d found it on a search, but
ignored it because of the cost.

Jamie

Jamie - just a note, I had to convert the latest FreeTDS package (0.63
at the time I think) into a dports package and install it, rather than
use the existing darwin ports version… things might be better now,
it was a few months ago.

Anyway - best of luck!

  • james

Thanks. You guys have convinced me to look at the Actual stuff.

Jamie

I messed around for hours trying to get the freeTDS drivers to work
correctly under Mac OS X and I finally gave in and bought the driver
from Actual Technologies, which is very easy to setup. This was
several months ago, so maybe the freeTDS drivers are easier now.

James, I would be interested in hearing how you did your setup.


Joe C.

James and Joe:

Have either of you successfully used the Actual driver successfully
with DBI? I thought I’d try that before Rails, but I keep getting
errors and am wondering if I’ve missed a step.

irb(main):004:0> dbh = DBI.connect
(‘DBI:ODBC=thedb’,‘Login’,‘somePassword’)
TypeError: is not a class/module
from /opt/local/lib/ruby/vendor_ruby/1.8/dbi/dbi.rb:499:in
load_driver' from /opt/local/lib/ruby/vendor_ruby/1.8/dbi/dbi.rb:401:in_get_full_driver’
from /opt/local/lib/ruby/vendor_ruby/1.8/dbi/dbi.rb:381:in
`connect’
from (irb):4

Thanks,

Jamie

jamie wrote:

I am about to start developing a Rails on my Mac for a client. The
app is connecting to a legacy system that uses SQL Server. Should I
follow the instructions at
Peak Obsession
HowtoConnectToMicrosoftSQLServerFromRailsOnLinux

or, does anyone have Mac OS-specific instructions?

Thanks,

Jamie O-H

oops!

Here follows a huge copy-paste of my FreeTDS/iodbc/SQLServer notes:

FREETDS

Get yourself the latest build of FreeTDS (0.63 as of writing this),
and build it like so:

cd /usr/local/src
curl -O
ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zxvf freetds-stable.tgz
cd freetds-0.63
./configure

At this point, we need to hack the generated libtool. Somewhere around
line 205 you should see:

archive_cmds="$CC $(if test .$module = .yes; then echo -bundle;
else echo -dynamiclib; fi) $allow_undefined_flag -o $lib $libobjs
$deplibs $linkopts -install_name $rpath/$soname $verstring"

Basically you need to remove the $deplibs in that line.

make
sudo make install

You can now test this by trying to connect to an MS SQL Server. To do
this, we’re using the tsql tool that is compiled along with FreeTDS:

$ tsql -H 10.9.0.95 -p 1147 -U sa
locale is “C”
locale charset is “US-ASCII”
Password:
1> use northwind
2> go
1> select count (*) as “Num” from customers
2> go
Num
91
1> exit

ODBC Administrator

ODBC Administrator

created by James A.

Firstly, add the driver under the “Drivers” tab.

Then you almost certainly want to create a User DSN, with the parameters

* Server e.g. localhost
* Database e.g. Northwind
* UID e.g. Administrator
* PWD
* Port e.g. 1147

This data gets stored in ~/Library/ODBC/odbc.ini. Any problems, you
can hack at that.

An entry should look like this:

[Redcats]
Driver = /opt/local/lib/libtdsodbc.so
Description = Redcats Development Database
Server = 10.9.0.95
Host = localhost\TESTSQL2
Port = 1147
Database = redcats_dev
UID =
PWD =
TDS_Version = 8.0

I’m not sure if you need to keep the ~/.freetds.conf in sync or not,
but i tend to. You need an entry to correspond with each ODBC entry:

[global]
tds version = 8.0

[Redcats]
host = GBLON1SQM27
port = 1147

… might be useful.

  • james