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

"My heart aches and a drowsy numbness pains my sense. as though of CGI::Session I had bummed..."
#!/usr/bin/perl -w # Import the modules use strict; use CGI::Session; use CGI::Pretty qw(:standard); use HTML::Template; use DBI; # various config parameters my $host = 'localhost'; my $db = 'dem.sqlite'; my $dbtype = 'SQLite'; #my $table = 'sessions'; my $dbuname = ''; my $dbpwd = ''; my $login_limit = 3; # create a new database connection my $dbh = DBI->connect("dbi:$dbtype:$db", '', '', {PrintError => 1, Ra +iseError => 1}); # The session is initialized or recalled. The session allows checking +whether # the user is logged in or not. my $cgi = new CGI; my $session = new CGI::Session("driver:$dbtype", $cgi, {Handle => $dbh +}); my $cookie = $cgi->cookie(CGISESSID => $session->id);
causes the following error --
Use of uninitialized value in join or string at 
/Library/Perl/5.8.1/darwin-thread-multi-2level/DBI.pm line 529 
during global destruction.
        (in cleanup) Can't connect(   HASH(0x80ca40)), no database 
driver specified and DBI_DSN env var not set at 
/Library/Perl/5.8.1/CGI/Session/SQLite.pm line 133
Line 133 in the relevant module is thusly
$self->{SQLite_dbh} = $args->{Handle} || DBI->connect( $args->{DataSource}, $args->{User} || undef, $args->{Password} || undef, { RaiseError=>1, PrintError=>1, AutoCommit=>1 } );
Needless to say, this darn thing was working in another incarnation. I have no idea where I have screwed it up, and now it croaks with the above error. As far as I can see, I am too passing it the Handle, so it shouldn't even bother trying to make another DBI connection.

Googling produces many instances of similar error, but with all kinds of different reasons, mainly relating to some typo or permissions error in creating the handle. Funny thing is, my $dbh is just fine as I have tested it with test queries and it works well.

Any insights will be much appreciated even if they show me up in a silly light. Learning experiences are always a step in the right direction.

Gracias.

Replies are listed 'Best First'.
Re: problem with CGI::Session / DBI connection
by antirice (Priest) on Mar 02, 2004 at 08:08 UTC

    You may want to try adding a $session->close(); at the end of your script to avoid the global destruction (it's what I had to do for CGI::Session::MySQL).

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

      You may want to try adding a $session->close(); at the end of your script to avoid the global destruction (it's what I had to do for CGI::Session::MySQL).
      Thanks for the advice, but that is not the problem at all. I have figured that because of my error ("Can't connect....") the session itself is not being created. Nothing is being stored in the sessions table in the database. Since I am passing a valid Handle, the script should connect to my database, and post the session values in the table. But that itself is failing.

      My question has now changed a bit and become thus -- I am looking for advice on session management for web applications. The mechanism should be cross-platform (run at least on Mac OS X and Windows) and cross webserver (Apache and IIS) and integrate with a few cross-platform storage mechanisms (databases). More than anything, the mechanism should be well-supported (at least a well frequented mailing list).

      CGI::Session seems like a wonderful module and I have mostly had luck with it. But there doesn't seem to be a community behind it. There is a moribund-ish mailing list.

      Apache::Session seems to be well-supported (can Google a lot of activity on it), but doesn't seem to be cross-platform (no PPM for Windows).

      Surely this must be a common problem solved by Perl coders on Windows. Any guidance would be much appreciated.

      Update: Never mind. Found Apache-Session ppd on http://theoryx5.uwinnipeg.ca/ppmpackages/ so that might provide me a workaround. Would still like to figure out what is causing CGI::Session to choke. It is a nice, simple module. Too bad I can't find an active mailing list behind it.

        I have figured that because of my error ("Can't connect....") the session itself is not being created.
        Well doesn't this give you a clue? If youare getting this error then the handle _IS NOT_ valid when you pass it in. SOmething somewhere else is possibly closing the ahndle before it is used here.

        CGI::Session works very well on all systems where I have used it (Windows, Linux, Solaris and HP-UX) with severeal different databases, but always with Apache never IIS (except in testing at one site where it currently runs okay on a test bed but was never put into production).

        As for CGI::Session, mail the author, he usually responds very quickly. I think he might also have a wiki or some such on his website.

        jdtoronto