in reply to perl db connection problems

If you have isolated the problem to the connect it would make sense to see what DBI says don't ya think?

my $dbh = DBI->connect("dbi:$db_type:$db_name", $db_username, $db_pass +word, @_ ) or confess( "Could not connect to database\n" . $DBI::errstr ); sub confess { print "Content-Type: text/html\n\n" . shift }

cheers

tachyon

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

Replies are listed 'Best First'.
Re: Re: perl db connection problems
by foobarbaz (Initiate) on Sep 15, 2003 at 14:21 UTC
    Yep, did that. The errstr simply says: DBI connect('Oracle7','***',...) failed: line 18

      It would help to show some code and the exact error message (by all means s/real_username/username/ s/real_password/password/ s/real_ip/x.x.x.x/ etc). The actual error message in all its exacting detail is typically relevant. Do you actually get '***', .... ? When a script runs on the command line (as user you presumbably, IP ? localhost) you need to understand that under CGI it probably runs as user ? apache ? nobody, IP ? real_ip. In other words the environment is different. It seems as though you are connecting to a remote DB which will have in it a remote access perms table that might look like:

      user perms you@somewhere * you@% *

      That's fine when you try to connect but not so good when apache@perhaps_some_other_ip tries to connect. If that is not the problem you also possibly have a firewall between you and the remote DB. DBs connect on unusual ports, and you can punch holes through firewalls on a global or per user basis.....

      cheers

      tachyon

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

        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