problems with Perl - DBD::ODBC

Constantin Vasilyev <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
Hi All,


I'm a heavy user of FreeTDS. Normally I use Sybase::DBlib which works like a charm for me,
but this time I need to figure out how to deal with DBD::ODBC.

The problem I'm facing is - the ODBC driver doesn't seem to look into $SYBASE/interfaces (or ~/.interfaces) files.
It only takes in account freetds.conf files.

Also, it seems to ignore $TDSDUMPCONFIG environment variable. $TDSDUMP, however, works fine.

Is any of the above expected for DBD::ODBC, or its just me doing something wrong?



Here's the snippet of the code I'm using:

-------------------------------------------------------------------------------------------------------
> cat ~/tmp/dbi.pl 
#!/opt/perl-5.8.8/bin/perl                                                                                                                                        

BEGIN {
   $ENV{'SYBASE'} = '/export/home/sybase/clients-mssql/freetds-0.82';
}

use strict;
use lib '/export/home/sybase/clients-mssql/freetds-0.82/perl';
use DBI;

my $dbh = DBI->connect('dbi:ODBC:driver=TDS;servername=MSSQLSERVER;database=test;app=dbi_test', 'username', 'password') || die;
print "Ok";

-------------------------------------------------------------------------------------------------------


There's /export/home/sybase/clients-mssql/freetds-0.82/interfaces file which resolves MSSQLSERVER into valid server:port pair.
All Sybase::DBlib scripts I'm working with use that file just fine, but the ODBC driver doesn't.
I don't even see an attempt to open it in strace output:

> strace ~/tmp/dbi.pl 2>&1 | egrep 'interfaces|freetds.conf'
open("/home/vasilyev/.freetds.conf", O_RDONLY) = 3
open("/export/home/sybase/clients-mssql/freetds-0.82/etc/freetds.conf", O_RDONLY) = 3
read(3, "#   $Id: freetds.conf,v 1.12 200"..., 4096) = 1102
read(3, "#   $Id: freetds.conf,v 1.12 200"..., 4096) = 1102
> 

only ~/.freetds.conf and /export/home/sybase/clients-mssql/freetds-0.82/etc/freetds.conf are tried.



If I add something like:

[MSSQLSERVER]
      host = my_test_server
      port = 1433

into one of those freetds.conf files the script works "Ok", if not - it fails with this message:

> ./dbi.pl
DBI connect('driver=TDS;servername=MSSQLSERVER;database=test;app=dbi_test','username',...) failed: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (SQL-08001) at ./dbi.pl line 12
Died at ./dbi.pl line 12.
>


My attempts to set $TDSDUMPCONFIG environment variable didn't make any effect:

> TDSDUMPCONFIG=stdout ./dbi.pl
DBI connect('driver=TDS;servername=MSSQLSERVER;database=test;app=dbi_test','username',...) failed: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (S
QL-08001) at ./dbi.pl line 12
Died at ./dbi.pl line 12.
>

but $TDSDUMP works as expected:


> TDSDUMP=stdout ./dbi.pl
log.c:190:Starting log file for FreeTDS 0.82
        on 2011-03-30 22:53:36 with debug flags 0x4fff.
iconv.c:197:names for ISO-8859-1: ISO-8859-1
iconv.c:197:names for UTF-8: UTF-8
iconv.c:197:names for UCS-2LE: UCS-2LE
iconv.c:197:names for UCS-2BE: UCS-2BE
iconv.c:363:iconv to convert client-side data to the "UTF-8" character set
iconv.c:516:tds_iconv_info_init: converting "UTF-8"->"UCS-2LE"
iconv.c:516:tds_iconv_info_init: converting "ISO-8859-1"->"UCS-2LE"
login.c:405:IP address pointer is empty
login.c:407:Server MSSQLSERVER not found!
mem.c:563:tds_free_all_results()
error.c:574:SQLError((nil), 0x13e321e0, (nil), 0x7fff7d63aae0, 0x7fff7d637e64, 0x7fff7d63a650, 513, 0x7fff7d637e6e)
error.c:510:_SQLGetDiagRec(2, 0x13e321e0, 1, 0x7fff7d63aae0, 0x7fff7d637e64, 0x7fff7d63a650, 513, 0x7fff7d637e6e)
error.c:574:SQLError((nil), 0x13e321e0, (nil), 0x7fff7d63aae0, 0x7fff7d637e64, 0x7fff7d63a650, 513, 0x7fff7d637e6e)
error.c:510:_SQLGetDiagRec(2, 0x13e321e0, 1, 0x7fff7d63aae0, 0x7fff7d637e64, 0x7fff7d63a650, 513, 0x7fff7d637e6e)
odbc.c:3680:SQLFreeHandle(2, 0x0x13e321e0)
odbc.c:3706:_SQLFreeConnect(0x13e321e0)
odbc.c:3680:SQLFreeHandle(1, 0x0x13c70e80)
odbc.c:3744:_SQLFreeEnv(0x13c70e80)
DBI connect('driver=TDS;servername=MSSQLSERVER;database=test;app=dbi_test','username',...) failed: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (SQL-08001) at ./dbi.pl line 12
Died at ./dbi.pl line 12.



That all seems quite strange  ...

And, almost forgot to mention, I'm running 0.82 stable.


Thanks for reading this and for any suggestions,



Constantin Vasilyev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.