After a *lot* of faffing about, I’ve finally managed to get Perl DBI::ODBC talking to a sql server database. For future reference, this post is useful, as is this one. The relevant config files on RHEL6 are
/etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS driver (Sybase/MS SQL) v0.91
Driver = /share/apps/freetds_0.91/lib/libtdsodbc.so
Setup = /share/apps/freetds_0.91/lib/libtdsodbc.so
UsageCount = 1
FileUsage = 1
/etc/odbc.ini
[CRIS]
Driver = FreeTDS
Server = x.x.x.x
Port = 1433
TDS_Version = 7.0
Database = MyDatabaseName
/path/to/freetds/etc/freetds.conf.
[MSSQL]
host = x.x.x.x
port = 1433
tds version = 7.0
test that odbc and freetds are working first:
/path/to/freetds/bin/tsql -S MSSQL -U Username -P Password -D Databasename
isql -v MSSQL Username Password
And then in perl
use DBI;
my $dsn = ‘dbi:ODBC:DSN=CRIS;’;
my $dbh = DBI->connect($dsn, $db_user, $db_pass);
# do some stuff with database
$dbh->disconnect;
I’m going to hunt you down and kiss you on the mouth. The ‘faffing about’ I was doing was leaving bloody scars on my forehead. There may have been references in other posts to what you showed in /etc/odbcinst.ini but I didn’t see them and that proved to be what I was lacking – that plus your elegant test script. Thanks for faffing until you were able to provide this answer. Now I can get a LOT done.
I should have also mentioned, I was doing this in ubuntu – I just had to find the alternate locations:
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
for the odbcinst.ini file.