in reply to Re^2: 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

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.

Replies are listed 'Best First'.
Re^4: perl w/ DBI connectiong to MSSQL, not reporting SQL server trigger errors
by chauzer (Novice) on Jan 06, 2005 at 20:28 UTC
    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.