EvanCarroll has asked for the wisdom of the Perl Monks concerning the following question:

This is showing in my apache error.log:
[Wed Oct 12 22:13:18 2005] [notice] Apache/1.3.33 (Debian GNU/Linux) m +od_ssl/2.8.24 OpenSSL/0.9.7g mod_perl/1.29 configured -- resuming nor mal operations [Wed Oct 12 22:13:18 2005] [notice] Accept mutex: sysvsem (Default: sy +svsem) [Wed Oct 12 22:13:18 2005] [error] Can't connect to data source Pg:dbn +ame='rodneyd', no database driver specified and DBI_DSN env var not s et at /usr/local/share/perl/5.8.7/Apache/DBI.pm line 146\n [Wed Oct 12 22:13:18 2005] [error] Can't connect to data source Pg:dbn +ame='rodneyd', no database driver specified and DBI_DSN env var not s et at /usr/local/share/perl/5.8.7/Apache/DBI.pm line 146\n [Wed Oct 12 22:13:18 2005] [error] Can't connect to data source Pg:dbn +ame='rodneyd', no database driver specified and DBI_DSN env var not s et at /usr/local/share/perl/5.8.7/Apache/DBI.pm line 146\n [Wed Oct 12 22:13:18 2005] [error] Can't connect to data source Pg:dbn +ame='rodneyd', no database driver specified and DBI_DSN env var not s +et at /usr/local/share/perl/5.8.7/Apache/DBI.pm line 146\n
I have this as my apache httpd.conf perl stanza:
PerlModule Apache::DBI PerlModule Apache::Session::Postgres PerlModule Apache::Cookie PerlRequire /etc/apache-perl/db.pl
db.pl:
my $dsn = 'rodneyd'; my $usn = 'postgres'; Apache::DBI->connect_on_init(qq{dbi:Pg:dbname=$db}, $usn, '' ) || die +"bleh"; Apache::DBI->setPingTimeOut($dsn, 30 ); 1;
Any ideas why I'm getting this error? Or what to do about it, I have tried setting the env variable in apache and in $ENV{DBI_DSN} no joy.


update #1.
Fixed typo, The error from the error.log is comming from my auctual web page which connects with the following :
$dbh = DBI->connect("dbi:Pg:dbname=rodneyd",q/postgres/,"",{AutoCommit + =>0, RaiseError=>1, PrintError=>0}) || die "Could not Connec t to DB".$dbi::errstr;
I assume that works, because the database ran fine with that exact string before I started to use Apache::DBI, and it pulls from the database fine.

UPDATE!!! LEARN SOMETHING FROM THIS

Apache aparently doesn't update the files in the PerlRequire pragma from restart, they must be cached somewhere, I shut down computer and everything worked. Start/stop fails to update this as well. Here is the kicker, apache-perlctl has a 'graceful' arguement that restarts it with a different signal. That forced apache to update my db.pl file. Joy at last. Things work.


Update It seems as if it might be the duration in between the start/stop.

UPDATE!!! LEARN MORE FROM THIS

I believe this to be a bug in DBI::Apache too, because of the crappy error message. It would apear as if the problem was in the dsn. To get the error again all one must do is seperate the dbi/driver fields with two colons rather than one.

IE. this works
Apche::DBI->connect_on_init(qq{dbi:Pg:dbname=$db}, $usn, '' ) || die;

IE. this doesn't. (And, yeilds the aforementioned error.).
Apche::DBI->connect_on_init(qq{dbi::Pg:dbname=$db}, $usn, '' ) || die;

While I understand why this works, or fails to work, this error message is sort of deceptive, and this could have been resovled with a simple regex in DBI::dsn_parse. I had probably went back and forth a few times on the dsn to hash this out. The first error could have been the spelling error jbrugger pointed out, and each time afterward it could have been the failure to update, without waiting inbetween the start/stop.


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re: No database driver specified and DBI_DSN env var not set
by jpeg (Chaplain) on Oct 13, 2005 at 04:17 UTC
    It seems Apache::DDI doesn't know what database to connect to. It looks like the DSN is incomplete. Where do you assign a value to $db in db.pl?

    The next thing I see is that you're using a single word as your $dsn. By convention a $dsn string takes the form

    dbi::driver::dbname;host=$host;port=$port;
    So once you fix the error in the connect_on_init arguments then setPingTimeout might not like the $dsn you're giving it.
    --
    jpg
      I tried your suggestions as well to no avail, I should add too I'm using sockets rather than tcp/ip. Thanks for the suggestion.


      Evan Carroll
      www.EvanCarroll.com
Re: No database driver specified and DBI_DSN env var not set
by jbrugger (Parson) on Oct 13, 2005 at 04:23 UTC
    Sure the error comes from there? might be just a typo somewhere, your error-log says:
    rodneyd while your dp.pl points to
    rodneydr

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      Good observation, that would have definitly caused a problem; however, unfortunatly it wasn't the source of this one. I must have made that in my hectic attempt to get this working. I have changed the parent node to reflect the current, more correct state.


      Evan Carroll
      www.EvanCarroll.com
Re: No database driver specified and DBI_DSN env var not set
by randyk (Parson) on Oct 13, 2005 at 04:55 UTC
    Are there any special environment variables that your database needs? You might have to use PerlSetEnv or PerlPassEnv to set these so that mod_perl is aware of them.
Re: No database driver specified and DBI_DSN env var not set
by jonix (Friar) on Nov 23, 2005 at 14:40 UTC
    Many thanks and EvanCarroll++,
    this node saved me a lot of headache indeed! I guess these are common DBI beginners gotchas.

    Cheers,
    jonix