in reply to Re: perl w/ DBI connectiong to MSSQL, not reporting SQL server trigger errors
in thread perl w/ DBI connectiong to MSSQL, not reporting SQL server trigger errors

For debugging purposes, it's almost better not to wrap it in eval. $dbh->{RaiseError}=1 will cause each DBI method to die with the generated error message, which by default will print to STDERR.

Anima Legato
.oO all things connect through the motion of the mind

  • Comment on Re^2: perl w/ DBI connectiong to MSSQL, not reporting SQL server trigger errors

Replies are listed 'Best First'.
Re^3: perl w/ DBI connectiong to MSSQL, not reporting SQL server trigger errors
by runrig (Abbot) on Jan 06, 2005 at 19:14 UTC
    You are correct, depending on whether or not you want the rest of the script to continue. But rather than setting $dbh->{RaiseError} = 1 I usually prefer adding a {RaiseError => 1} argument to the connect, so that even connect errors are caught by RaiseError.
      After using eval around my DBI code, when the page loads, i get this following error: bind_col: column 2 is not a valid column (1..1) at /var/www/cgi-bin/archtmltest.pl line 306, line 8641. It's weird though. It only happens the first time i visit the page. Once I refresh it once, it's fine. And everytime i visit the page after that it's fine. It's only the very first time i visit the page that error shows up. Any ideas why? Thanks
        Is it bad in any way to leave the code like this?
        No, it's perfectly perlish. Though you can now take out the checks you already had (if you haven't already taken them out). E.g. change this:
        if ($dbh = DBI->connect(...)) { ...
        to this:
        my $dbh = DBI->connect(...., {RaiseError => 1});
        Again, I'll also recommend using strict.