So I’m no Ruby expert but I’ve need of connecting Rails to a MSSSQL Server 2000 DB. I just wanted to offer a bit more explanation at the FreeTDS and iODBC pieces of the installation.
UBER BIG DISCLAIMER: I’m no Rails export (had to say it again) so although I can try to help, please don’t hate me if for some reason these instructions don’t work for you; I’m just trying to help out. I’m mostly using the instructions from the wiki.rubyonrails.com site.
First we need to install FreeTDS (version 0.63 as of this writing). I used the freetds docs as a guide:
[source:ruby]
Compile-time settings (established with the “configure” script):
Version: freetds v0.64
MS db-lib source compatibility: no
Sybase binary compatibility: unknown
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: yes
unixodbc: no
[/source]
Now let’s check and see if we can connect to one of our SQL Server DB’s.
[source:ruby]
[MySQLServer]
host = mySQLdb.somewhere.com
port = 1433
tds version = 8.0
[/source]
Next configure your ODBC ini files
odbcinst.ini
[source:ruby]
[ODBC Drivers]
JDBC = Installed
[JDBC]
Description = Sybase JDBC Server
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
[/source]
odbc.ini
[source:ruby]
[ODBC Data Sources]
MySQLServer = JDBC
[MyDSN]
Driver = /usr/local/lib/libtdsodbc.so
Description = Description of this database connection
Trace = yes
TraceFile = /tmp/odbc.log
Servername = MySQLServer
[/source]
*NOTE: You need to make sure that the “Servername” in this step is the same as the value in Step 3 of the previous section, or else you may twist your head over why it won’t work.
Now test your connection by running:
[source:ruby]iodbctest “dsn=MySQN;uid=USERNAME;pwd=PASSWORD”[/source]
And a command prompt should display on the screen. You can now try and type in any SQL statement (i.e., SELECT * FROM MyTable) and be amazed at the code shooting across the screen.
OK, so that finishes getting iODBC and FreeTDS connecting. Once again, this was just a “spell-it-out-for-those-who-need-it” version of the first half of the official wiki.rubyonrials documentation.
See RubyOnRails using MSSQL Server and Free DS Part 2
Technorati Tags: Apple, SQL Server 2000, Ruby On Rails
[...] So here’s the rest of my getting Rails to connect to MSSQL experience … (See Part 1) Since I used Hivelogic’s setup (you can also install from Darwin .. which I’ll probably install on my laptop which I’ve already done and will forever ALWAYS do) for my Ruby and Rails installation, I just went back to my usr/local directory to do the rest of the work. I should also note that you’ll need to have Ruby and Rails installed at this time in order for the commands to actually work (yea, I know it’s obvious, but just needed to say). [...]
Hello, I’m writing to ask if you have any experience connecting to a Sybase DB with Rails. I’ve followed your outlined steps and running basic tests works, but from within Rails I get the following error:
`establish_connection’:ActiveRecord::AdapterNotFound: database configuration specifies nonexistent sybase adapter
If I set the adapter name to sqlserver everything starts up fine, but hangs when I try to do any ActiveRecord activity.
Do you know if there are special instructions for setting up FreeTDS to work with Sybase and rails?
Thanks,
Hey binkly,
I’m really sorry but I’ve not used Rails with Sybase at all.
Offering my $0.02, it looks like a problem with your adapter. Forgive me if you’ve already seen this, but are you using the sybase anywhere adapter from the wiki.rubyonrails site? If not, I’d suggest trying it out and then trying to connect again.
tst
tst
tst
tst
tst
tst
tst
tst
tst
tst