Not tested, so dunno if it's correct or not, also, very likely unsafe especially if used in multithreaded
try:
...
...
except DbError:
var
err = cast[DbError](getCurrentException())
msg = err.msg
EDIT: Ah, sorry, I just realized that you want error code instead of the message.