in reply to Re: Re: Re: perl db connection problems
in thread perl db connection problems

Hi,

Here's some code below:

#!c:\Perl\bin\perl.exe use strict; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser set_message); set_message("There has been a problem submitting this form. Please con +tact the Reception desk."); $CGI::POST_MAX=1024 * 100; # max 100k posts $CGI::DISABLE_UPLOADS = 1; # no uploads allowed use Data::Dumper; my $user='foo'; my $pwd='bar'; my $dbh = DBI->connect('dbi:ODBC:Oracle7', $user, $pwd, { RaiseError = +> 1 }) or die "Failed to connect to $DBI::errstr\n"; my $sql = "insert into users (surname,forename,title,nationality,dob,g +ender,email,status,created,created_by) values ('Smith','Fred','Mr','UK','27031972','m','f.smith\@hotmail.com','Frien +ds',SYSDATE,'SelfReg')"; print "SQL is [$sql]\n"; my $sth = $dbh->prepare($sql) || do { die "Failed to prepare\n" }; $sth->execute; $sth->finish; $dbh->disconnect;

The error message from the log is:

c:\PROGRA~1\APACHE~1\apache\cgi-bin\TEST_I~1.CGI: DBI connect('Oracle7 +','foo',...) failed: at c:\PROGRA~1\APACHE~1\apache\cgi-bin\TEST_I~1 +.CGI line 18

The failure is at the connect().

How can I test to see if it's a port/connection problem that's causing it?
Many thanks,
Mike

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: perl db connection problems
by tachyon (Chancellor) on Sep 17, 2003 at 15:20 UTC

    First is the DB remote ie on another boxen as asked? Anyway I expect it is so try this:

    $user = 'foo@localhost';

    Replace localhost with the external NUMERICAL (probably ;-) IP of your box - the one it is going to use to connect to Oracle.

    Now ITFM it is noted that:

    If the environment variable DBI_AUTOPROXY is defined (and the driver i +n $data_source is not ``Proxy'') then the connect request will automa +tically be changed to: $ENV{DBI_AUTOPROXY};dsn=$data_source DBI_AUTOPROXY is typically set as ``dbi:Proxy:hostname=...;port=...''. + If $ENV{DBI_AUTOPROXY} doesn't begin with 'dbi:' then ``dbi:Proxy:'' + will be prepended to it first. See the DBD::Proxy documentation for +more details.

    So it may well be that your actual connect is specifying diffenerent details like the hostname and port perhaps? Hostnames and ports are handy connecting to remote DBs. But I am speculating because you don't supply enough detail. Still this is one of my current working theorums. Perhaps this env variable is set for you but not apache. To test the ENV dump in off the command line where it is working and dump it in you CGI before it explodes. If there are differences you could do worse than to fix them and see if the problem goes away.

    Thinking about it on Win32 with ODBC database access you set up (or the installer does) a mapping from a DSN (Data Source Name) to the actual DB. Do this. Start|Run|odbcad32. You will see a dialog. I expect that you have a user DSN (which lets you connect to Oracle) but Apache does not. Add a system DSN and the problem should go away. If that is the problem. But then other people could perhaps get a the DB which may be another problem. Too many problems for one night.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Many thanks for the reply.

      I set System DSN (only User DSN was set before) and it now connects fine.

      Many thanks for you help.

      foobarbaz

        Glad you got it going. As an aside I would just point out that if you have a persistent problem the best idea is to repost (referencing the original node using [id://xxxxxxx] where xxxxxxx is the name or number of the node. This puts it back on the radar as it drops off newest nodes (an so the replys will diminish++) after 24 hours. Fastest replies occur during euro and US working hours.

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print