http://www.perlmonks.org?node_id=1049307

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

Hi

I have an error handler in some Perl code which connects to SQL Server via ODBC. I have the following error handler defined
sub ErrorHandler { my ($sqlstate, $msg, $nativeerr) = @_; # Strip out all of the driver ID stuff $msg =~ s/^(\[[\w\s:]*\])+//; print $msg; print "===> state: $sqlstate msg: $msg nativeerr: $nativeerr\n"; return 1; }
I'm getting this error and wish to skip it
DBD::ODBC::st execute failed: [Microsoft][SQL Server Native Client 11. +0][SQL Server]Arithmetic overflow error converting float to data type + numeric. (SQL-22003)
Being fairly new to Perl I'm not sure how to change the error handler to be able to ignore this particular error

So something like if nativerr = 22003 return 0 else return 1

Any help appreciated

Replies are listed 'Best First'.
Re: ODBC Sql Server error handling
by Laurent_R (Canon) on Aug 13, 2013 at 19:00 UTC

    Your ErrorHandler routine does not seem to be connecting to SQL. It is just formating the error message returned by SQL and printing the output. You could have something like:

    return if $msg =~ /SQL-22003/;

    right before the comment "#Strip out...". The error will not be printed, but I doubt it will solve your underlying problem.

Re: ODBC Sql Server error handling
by mje (Curate) on Aug 14, 2013 at 09:13 UTC

    It looks to me (because your error handler expects a state, message and native) that your error handler is one set up via odbc_error_handler. If you return 0 from this handler the error is ignored. However, you might want to also read HandleError for DBI (rather than DBD::ODBC) as it specifically tells you how to ignore an error with set_err although there are issues you need to be aware of.