http://www.perlmonks.org?node_id=1033752


in reply to Re: fail: Linux Perl-DBI to SQL Server
in thread fail: Linux Perl-DBI to SQL Server

Solved

I have figured out what is going on and succeeded in connecting. The root of the problem is understanding the concept of a DSN. The basic syntax is:


dbi:ODBC:dsn_name

where dsn_name is a string that is used to index into a section header of one of the .ini files (e.g. odbcinst.ini).

The problem is that there is an alternate syntax known as DSN-less connection strings (curly brackets) which essentially contains connection information inline. For some reason I never got this to work correctly, I believe because the DSN-less syntax never connected to the location of the driver .so file. When I refashioned my example to use DSN syntax the example succeeded. My updated code fragment looks like this:

% cat simple.pl #!/usr/bin/perl use DBI; my $dsn="dbi:ODBC:DSN=tul1system"; my $dbh = DBI->connect($dsn, "user334", "2BEvPog"); if (! defined($dbh) ) { print "***Error connecting to DSN\n"; print "***Error was:\n"; print "***$DBI::errstr\n"; # $DBI::errstr is the error }

Note that the other information like database name and IP address now come from the .ini file.