Why do I get "SQLSetConnectOption err=-2" errors in my Perl scripts
When running a Perl script using DBD::ODBC linked with the unixODBC Driver Manager, if you get:
DBI->connect(test) failed: (Unable to fetch information about the error) (DBD: dbd_db_login/SQLSetConnectOption err=-2) at perl_e1.pl line 9
the cause may be the combination of lazy linking and RTLD_GROUP
.
- If you're using Perl directly from the shell:
Did
make test
succeed when building DBD::ODBC?make test
setsPERL_DL_NONLAZY
to1
. If lazy linking is the problem, it won't be uncovered bymake test
.Try running your Perl script again with the environment variable
PERL_DL_NONLAZY
set to1
.If this solves the problem, you probably have a unixODBC Driver Manager that sets the
RTLD_GROUP
flag todlopen
.If you're using the unixODBC Driver Manager distributed with the Easysoft ODBC-ODBC Bridge, please let us know the name of your ODBC-ODBC Bridge distribution file. If you're using unixODBC 2.2.6 or later, you can rebuild unixODBC with the
configure
option--enable-rtldgroup=no
. If you are using unixODBC 2.2.5 or earlier, you need to stop unixODBC using theRTLD_GROUP
flag inlibltdl/ltdl.c.
Edit
libltdl/ltdl.c
in the unixODBC source tree, search for adlopen
call usingRTLD_GLOBAL
(which isORed
withLT_LAZY_OR_NOW
). DeleteLT_GLOBAL |;
. For example:lt_module module = dlopen (filename, LT_GLOBAL | LT_LAZY_OR_NOW);
becomes:
lt_module module = dlopen (filename, LT_LAZY_OR_NOW);
- If you're using Perl as an Apache CGI program without
mod_perl
Try adding:
SetEnv PERL_DL_NONLAZY 1
to the
httpd.conf
file and restart Apache. Then follow instructions in the previous bullet point. - If you're using
mod_perl
under Apache:Set the environment variable
PERL_DL_NONLAZY
to1
, export it, and then restart Apache.If this solves the problem, you need to set and export
PERL_DL_NONLAZY
in yourapachectl
startup program.If this doesn't solve the problem and you're using a unixODBC Driver Manager newer than 2.2.6, rebuild unixODBC with the
configure
option--enable-rtldgroup=no
.
Easysoft build the unixODBC Driver Manager with the following configure
options:
./configure --prefix=/usr/local/easysoft/unixODBC --sysconfdir=/etc --enable-threads=no (or yes when building a thread-safe version) --enable-iconv=no --enable-drivers=no --enable-gui=yes (or no if you don't have X and QT)
To dlopen
unixODBC in an application, --enable-rtldgroup=yes
needs to be added to the unixODBC 2.2.6, 2.2.7, 2.2.8+ configure line.
We also use --enable-readline=no
on some platforms, because many newer machines don't have the libreadline
version that's present on our build machines (which are older, for backwards compatibility reasons).