Using DBD::ODBC in a CGI script under Apache

Using DBD::ODBC in a CGI script under Apache

am 06.07.2006 19:45:03 von scarmalt

--=_alternative 00618242C12571A3_=
Content-Type: text/plain; charset="US-ASCII"

I'm having a problem getting DBD::ODBC to work when invoked from a cgi
script (running under Apache).

Specifics ---

I have a test program which can be called from two different "drivers".
One is run from the command prompt:

>perl test_sql_flat.pl

The other from cgi script

http://development.server.in-house/cgi-bin/test_sql_page.pl

These scripts call a common module to do a simple DBI SELECT test.

The common module can be configured to use either an ODBC interface or an
Oracle interface.

Both work without problems when launched from the command prompt after
logging in as the web user.
But when invoked from a cgi setting, only the Oracle request works; the
ODBC returns

DBI connect('db2adrs','odbcread',...) failed: Specified driver could
not be loaded (SQL-IM003)(DBD: db_login/SQLConnect err=-1)

Any suggestions on how to fix this will be most welcome.

Thanks and regards,
Sam Carmalt

--=_alternative 00618242C12571A3_=--

Re: Using DBD::ODBC in a CGI script under Apache

am 06.07.2006 20:12:57 von Martin.Evans

On Thu, 2006-07-06 at 19:45 +0200, scarmalt@iec.ch wrote:
> I'm having a problem getting DBD::ODBC to work when invoked from a cgi
> script (running under Apache).
>
> Specifics ---
>
> I have a test program which can be called from two different "drivers".
> One is run from the command prompt:
>
> >perl test_sql_flat.pl
>
> The other from cgi script
>
> http://development.server.in-house/cgi-bin/test_sql_page.pl
>
> These scripts call a common module to do a simple DBI SELECT test.
>
> The common module can be configured to use either an ODBC interface or an
> Oracle interface.
>
> Both work without problems when launched from the command prompt after
> logging in as the web user.
> But when invoked from a cgi setting, only the Oracle request works; the
> ODBC returns
>
> DBI connect('db2adrs','odbcread',...) failed: Specified driver could
> not be loaded (SQL-IM003)(DBD: db_login/SQLConnect err=-1)
>
> Any suggestions on how to fix this will be most welcome.
>
> Thanks and regards,
> Sam Carmalt

What platform are you running the CGI on?
I'm guessing UNIX but only from the command prompt shown above

What is the ODBC driver?
DB2? if so it will need DB2INSTANCE setting and exporting from you
Apache config although if this was the reason for the failure you'd get
a different error - like failed to allocate environment.

Are you using an ODBC driver manager and if so which one?

It is probably and environment issue. Something in you environment when
you log is a your web user which is required to load your driver which
is not passed on to CGI scripts by default - like LD_LIBRARY_PATH - see
SetEnv in the Apache configuration guide and examine your environment
when logged in as your webuser by running env.

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Re: Using DBD::ODBC in a CGI script under Apache

am 07.07.2006 01:29:51 von ron

On Thu, 06 Jul 2006 19:12:57 +0100, Martin J. Evans wrote:

Hi Martin

> What platform are you running the CGI on?
> I'm guessing UNIX but only from the command prompt shown above

If Windows, perhaps OP has mistakenly created a user DSN rather than a=
system
DSN?
--
Cheers
Ron Savage, ron@savage.net.au on 7/07/2006
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company

Re: Using DBD::ODBC in a CGI script under Apache

am 10.07.2006 10:00:30 von scarmalt

--=_alternative 002BFDF7C12571A7_=
Content-Type: text/plain; charset="US-ASCII"

Martin -

Thanks. The SetEnv in the httpd.conf did the trick.

I had been setting the needed environment variables at the beginning of
the my CGI script, but the ODBC driver apparently is run in the with the
initial CGI environment, not with one that has been modified.

Many thanks.

Regards, Sam Carmalt

--=_alternative 002BFDF7C12571A7_=--