Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

ODBC Sql Server error handling

by Anonymous Monk
on Aug 13, 2013 at 16:02 UTC ( #1049307=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


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 (Abbot) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1049307]
Approved by greengaroo
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-08-19 13:22 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (311 votes). Check out past polls.