[CDBI] Class::DBI opens database connection for each object?

Josh Tanski mortonjt at rochester.rr.com
Fri Apr 11 18:19:03 BST 2008


I have some classes setup as below - there are more classes similar to 
Readings that inherit from LoggerDB I've snipped to save space.

My script parses text files from a third party logging system to add 
them to the database - I'm trying out Class::DBI to save myself from 
having to write alot of basic CRUD SQL.  There's thousands of records in 
the log files and a reading object is created for each record - what 
happens is it dies with the following error after it creates roughly 950 
db records.  Netstat shows I have about that many tcp connections in 
TIME_WAIT, so my guess is I'm hitting a tcp socket limit.

DBI connect('dbname=dbname;host=localhost;port=5555','username',...)
Couldn't connect to localhost:5555/tcp: IO::Socket::INET: connect: 
Unknown error
  at C:/Perl/site/lib/DBD/PgPP.pm line 124
  at C:/Perl/site/lib/Ima/DBI.pm line 328

My question is what am I doing wrong - shouldn't there only be one 
database connection open and all db access going through that connection?

I'm running ActivePerl from the Windows XP command line.


use strict;
use warnings;
use DBI;

package LoggerDB;
use base 'Class::DBI';
'username', 'password');

package Reading;
use base 'LoggerDB';
Reading->columns(Primary => qw/reading_timestamp reading_name/);
Reading->columns(Others => qw/reading_value/);

More information about the ClassDBI mailing list