this destroy routine is definitely a problem (may or may not be the cause
of the error though) apache::dbi over-rides the dbi connect method in
order to check an internal hash of cached db handles so that an existing
connection can be returned rather than taking the performance hit of
establishing another connection....similarly, all disconnect methods under
apache::dbi are over-ridden to do nothing when they are called so existing
db handles remain persistant. 

Your code has a problem, however, in that after the disconnect method is
called you completely delete the hash element that contains the dbh
pointer. any subsequent connects will attempt to use a cached handle that
is actually gone which will generate an error. just take out the delete
bit and you should be all good.

-amen

PS> the reason it works sometimes is merely because your code is being
run by an apache child process for the first time. As soon as it is run
again by the same process it should fail.....

On Tue, 26 Oct 1999, James G Smith wrote:

> I am completely confused...
> 
> I have a couple of connections I use - one for general information, 
> another for authentication purposes.  I am wanting to use Apache::DBI 
> to cache the connections.
> 
> When running as httpd -X I have no problems whatsoever.  However,
> running as normal, it will work fine for a while (once through each
> daemon) and then start flaking out.  The following are the error
> messages that I do get:
> 
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 43
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 54
> [Tue Oct 26 21:02:49 1999] [error] access to /www/mod_perl/htdocs/user_admin/edit 
>failed for modperl.jamesmith.com, reason: invalid account
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 43
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 54
> [Tue Oct 26 21:02:54 1999] [error] access to /www/mod_perl/htdocs/user_admin/edit 
>failed for modperl.jamesmith.com, reason: invalid account
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 43
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 54
> [Tue Oct 26 21:04:59 1999] [error] access to /www/mod_perl/htdocs/user_admin/edit 
>failed for modperl.jamesmith.com, reason: invalid account
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 43
> DBI->connect failed: Lost connection to MySQL server during query at 
>/www/lib/perl/Fresh/DBI.pm line 54
> [Tue Oct 26 21:05:16 1999] [error] access to /www/mod_perl/htdocs/user_admin/edit 
>failed for modperl.jamesmith.com, reason: invalid account
> 
> I'm not looking so much for an answer (though that would be nice) but for
> a few pointers on where to look next.  I seem to get these errors with or
> without Apache::DBI.  The following is the cleanup routine:
> 
> sub DESTROY {
>   my $self = shift;
>   if($self) {
>     $$self{dbh}->disconnect;
>     delete $$self{dbh};  # required to properly disconnect 
>     $$self{user_dbh}->disconnect;
>     delete $$self{user_dbh};  # required to properly disconnect
>   }
> }
> 
> I have followed the directions in Apache::DBI and still get these results.
> (Thinking it might be the destruction *somehow* of the database handles.)
> Not sure why, but the delete statements are required without Apache::DBI
> to avoid the ``destroyed without disconnect'' error messages.
> --
> James Smith <[EMAIL PROTECTED]>, 409-862-3725
> Texas A&M CIS Operating Systems Group, Unix
> 

Reply via email to