[unixODBC-support] How to odbc.ini and odbcinst.ini -- or how to Server=??? in DSN-Less connect

Michael Higgins linux at evolone.org
Mon Jun 2 21:44:00 BST 2008


On Mon, 02 Jun 2008 17:48:47 +0100
Nick Gorham <nick.gorham at easysoft.com> wrote:

> Michael Higgins wrote:
> 
> >Hello list --
> >
> >The problem I've had is that none of the DRIVER definitions seem to
> >get picked up in SQLDriverConnect via perl-dbi.
> >
> >I use DBD::ODBC to connect. Using a defined DSN works, but I want a
> >distributable app.
> >
> 
> It should work as long as the Driver= line in odbc.ini points to a 
> driver in odbcinst.ini
> 
> so in odbcinst.ini
> 
> [MyDriver]
> Driver = /path/to/my/driver.so

So, this should be okay:

cat /etc/unixODBC/odbcinst.ini

[Default]
/usr/lib/libtdsodbc.so

[FreeTDS]
/usr/lib/libtdsodbc.so

I want to call my driver FreeTDS.

> and in odbc,ini a entry that matches would be
> 
> [MyDsn]
> Driver = My Driver
> 
> Then you could connect with
> 
> DSN=MyDsn

Which I want to avoid, users needing a DSN entry. So, this file is not
needed at all for my purpose, no?

> 
> or
> 
> Driver={My Driver}

Which would require users have some... something (not DSN?) configured.

(Why can't I just pass the path to the .so, I wonder?)

> I don;t have a FreeTDS entry, but this is much the same and works
> using the make test in the DBD module instalation
> 
> odbcinst.ini
> 
> [Easysoft ODBC-SQL Server]
> Driver     = /usr/local/easysoft/sqlserver/lib/libessqlsrv.so
> Setup       = /usr/local/easysoft/sqlserver/lib/libessqlsrvS.so
> Threading       = 0
> FileUsage       = 1
> DontDLClose     = 1
> UsageCount      = 1

Where are these last five options documented with the installation? Or
are they specific to this other driver you use for example?

> 
> Values passed to perl
> 
> DBI_DSN="dbi:ODBC:DRIVER={Easysoft ODBC-SQL 
> Server};Server=192.168.250.71;Database=Test"
> DBI_USER=test
> DBI_PASS=test
> 

. . .

Well, I went through this step-by-step. No joy, period. The only thing
that works is having this:

cat /etc/unixODBC/odbc.ini
[Default]
Driver          =  /usr/lib/libtdsodbc.so

And NOT specifying the driver in my connect string. (Which seems
totally in conflict with what you posted.)

To illustrate:

# mv /etc/unixODBC/odbc.ini /etc/unixODBC/odbc.ini.bak
# mv /etc/unixODBC/odbcinst.ini /etc/unixODBC/odbcinst.ini.bak
# vim /etc/unixODBC/odbc.ini
# cat /etc/unixODBC/odbc.ini
[Default]
Driver          =  /usr/lib/libtdsodbc.so

locate odbc |grep .ini
cat /home/myuser/.odbc.ini
[empty]

And in my script:

$DSN="Server=ip.add.of.svr;Port=1433;Database=thedb;UID=_user;PWD=_pass;";

$DB->connect("dbi:ODBC:$DSN",'','', { AutoCommit
=> 1, LongTruncOk=>1 }, { quote_char => '"',
          name_sep => '.' }
         );

So, I'm stumped. I wasted many frustrated hours following all the
how-tos and hints I found on the web, only to come upon this...
solution(?) quite by trial-and-error.

Now what? Should we try to discover the root of the conflicting
information, or should the unixODBC how-tos be updated, somehow? I was
about to uninstall it completely when I found it works, but just not
"as advertised". '-)

It appears like there may be some different assumptions with FreeTDS
and unixODBC. I just looked again at this: 

http://www.freetds.org/userguide/odbcinionly.htm
------------
ODBC-only configuration

An ODBC-only configuration relies solely on odbc.ini 
------------

So, how does this correspond/correlate with the docs for unixODBC? Were
you aware that this was a possible configuration for unixODBC?

And this seems important as well:

http://www.freetds.org/userguide/prepodbc.htm
-----------------
With version 0.60, the FreeTDS ODBC library started to see fuller
implementation. The driver was made able to read the connection
attributes directly from odbc.ini, rather than leaning on freetds.conf.
For installations that don't need db-lib and ct-lib, this ODBC-only
setup is simpler.
------------------

So. How about,
# mv /etc/freetds.conf /etc/freetds.conf.bak

Script still works. I'm totally baffled at this point. Do I even need
unixODBC? 

DBIx::Class::Storage::DBI::ensure_connected(): DBI Connection failed:
install_driver(ODBC) failed: Can't load
'/usr/lib/perl5/vendor_perl/5.8.8/i586-linux/auto/DBD/ODBC/ODBC.so' for
module DBD::ODBC: libodbc.so.1: cannot open shared object file: No such
file or directory at /usr/lib/perl5/5.8.8/i586-linux/DynaLoader.pm line
230.  at (eval 208) line 3
Compilation failed in require at (eval 208) line 3.
Perhaps a required shared library or dll isn't installed where expected
 at /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 839

I guess so, in order to build DBD::ODBC??? So, what's the solution? Is
it possible to get FreeTDS and unixODBC docs into some concordance? Or
is this a Gentoo bug, for example? I just noticed a proposed DBD-ODBC
ebuild is on the coming bugday list. Is this something that should be
addressed in that context, at the least?

Just a quick look at the web in this context led me to this:

http://www.nntp.perl.org/group/perl.dbi.users/2007/04/msg31307.html

How long has this been going on? This looks awfully similar to the
problem I had.

From that post:

"In reality, on UNIX no one writes a default section in their odbc.ini 
file so the misdirection to a
DEFAULT driver nearly always confuses."

Um, that's exactly how my configuration works, though I'm not
specifying Default, it would appear the [Default] section is read. From
that file.

http://www.nntp.perl.org/group/perl.dbi.users/2007/04/msg31300.html

Is this a good outcome?

The only answers he seems to have got was to use DBD::Gopher or
DBD::Sybase. 

Hope this helps someone keep the ODBC option available.

Cheers,

-- 
 |\  /|        |   |          ~ ~  
 | \/ |        |---|          `|` ?
 |    |ichael  |   |iggins    \^ /
 michael.higgins[at]evolone[dot]org



More information about the unixODBC-support mailing list