On Tue, 2004-10-26 at 15:52, Brian Dimeler wrote: > The connection code is actually in a Class::DBI > module, which gets use()'d by all of my scripts.
Bingo, that's the problem. Class::DBI uses Ima::DBI, which does not play well with Apache::DBI. It keeps its own connection cache in closures and Apache::DBI doesn't know about it. I plan to submit a patch for Ima::DBI to fix this, but in the meantime I am handling it by overriding db_Main and doing the connections myself. Here's the code I use: my $db_options = { RaiseError => 1, AutoCommit => 0, FetchHashKeyName => 'NAME_lc', ShowErrorStatement => 1, ChopBlanks => 1, RootClass => 'DBIx::ContextualFetch' }; # override default to avoid using Ima::DBI closure sub db_Main { my $dbh; if ( $ENV{'MOD_PERL'} and !$Apache::ServerStarting ) { $dbh = Apache->request()->pnotes('dbh'); } if ( !$dbh ) { # $config is my config object. replace with your own settings... $dbh = DBI->connect_cached( $config->get('DbDSN'), $config->get('DbUser'), $config->get('DbPass'), $db_options ); if ( $ENV{'MOD_PERL'} and !$Apache::ServerStarting ) { Apache->request()->pnotes( 'dbh', $dbh ); } } return $dbh; } sub dbi_commit { my $self = shift; $self->db_Main()->commit(); } sub dbi_rollback { my $self = shift; $self->db_Main()->rollback(); } Note that it was necessary to override dbi_commit and dbi_rollback as well because now Ima::DBI doesn't know about this handle. I also stashed the handle in pnotes() for some extra speed because Class::DBI requests it so frequently. Stashing in pnotes() is safe because it gets cleared out at the end of each request even if your code dies. Make sure you keep the other db options intact or various things in Class::DBI will break. - Perrin -- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html