in reply to OLE exception from ADODB.Connection

My guess is that your "closed" connection was never opened in the first place. The lines below to open the connection (excerpted from your code) have no error checking before or after them to make sure the connection is valid. If the connection can't be created, your program continues merrily as if everything was OK. You could be miles away from the original code that created the connection before you ever see problems.

my $conn = Win32::OLE->CreateObject('ADODB.Connection'); # Open a connection using the SQL Server OLE DB Provider LogIt( $fhDEBUG, "Opening ADODB connection") if $CONFIG{DEBUG} > 3; $conn->Open(<<EOF); $DSN EOF

Logging isn't enough. It only reports problems, it doesn't change the program flow to account for them.

Might be a good idea to add some error checking code and throw an exception or at least return undef immediately after the connection creation code when the connection fails.

Best, beth

Replies are listed 'Best First'.
Re^2: OLE exception from ADODB.Connection
by Mych (Initiate) on Apr 07, 2009 at 09:37 UTC

    Thanks Beth and Annon,

    I've ammended the code to log the conn status, as recommended by both of you, to see if I am making a connection. (BTW I tested the connection using the 'Test connection' at the end of the ODBC wizzard and that's fine.

    The ammedments are...

    my $conn = Win32::OLE->CreateObject('ADODB.Connection'); # Open a connection using the SQL Server OLE DB Provider # LogIt( $fhDEBUG, "Opening ADODB connection") if $CONFIG{DEBUG} > 3; $conn->Open(<<EOF); $DSN EOF # Added 07/04/09 on recomendation (Perl Monks) a check to see if DB + connection was really successfull. my $connStatus ="Not Set" if($conn->{State} == adStateOpen) { $connStatus = "Connection was a success"; } else { $connStatus = "Connection failed because "; $connStatus .= $conn->Errors(0)->{Description}; } #LogIt( $fhDEBUG, "COMPLETE: Opening ADODB connection") if $CONFIG{ +DEBUG} > 3; #changed above line to log status of connection LogIt( $fhDEBUG, $connStatus) if $CONFIG{DEBUG} > 3; # End of 07/04/09 changes

    I also commented out all the extra sql lookups so that I was only making one lookup per DB... unfortunately the error now is...

    CGI Timeout The specified CGI application exceeded the allowed time for processing +. The server has deleted the process.

    Nothing is logged to the DEBUG file at all

    I'll try some more experimenting... meanwhile if someone can spot something I've obviously missed out...let me know.

    Mych
    I have not failed... just found 100 ways that don't work YET!

      All, Thanks

      As you all rightly pointed out. I was not logging useful info in my debug file. The problem was a permissions issue to the DB. All DB's apart from CSSD had dbreader rights assigned to the IIS_User. My Bad.

      Mych
      I have not failed... just found 100 ways that don't work YET!