Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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:

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

Comment on ODBC Sql Server error handling
Select or Download Code
Re: ODBC Sql Server error handling
by Laurent_R (Parson) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1049307]
Approved by greengaroo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-12-20 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (98 votes), past polls