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 testsucceed when building DBD::ODBC?make testsetsPERL_DL_NONLAZYto1. 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_NONLAZYset to1.If this solves the problem, you probably have a unixODBC Driver Manager that sets the
RTLD_GROUPflag 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
configureoption--enable-rtldgroup=no. If you are using unixODBC 2.2.5 or earlier, you need to stop unixODBC using theRTLD_GROUPflag inlibltdl/ltdl.c.Edit
libltdl/ltdl.cin the unixODBC source tree, search for adlopencall usingRTLD_GLOBAL(which isORedwithLT_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_perlTry adding:
SetEnv PERL_DL_NONLAZY 1
to the
httpd.conffile and restart Apache. Then follow instructions in the previous bullet point. - If you're using
mod_perlunder Apache:Set the environment variable
PERL_DL_NONLAZYto1, export it, and then restart Apache.If this solves the problem, you need to set and export
PERL_DL_NONLAZYin yourapachectlstartup 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
configureoption--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).