You might be able to use the LogCapture() function which allows you capture messages sent back to the JMP log by function calls.
Something like this :
RetryCount = 0
ErrMsg = LogCapture(<your SQL connection string>);
while( contains(ErrMsg, <some error string you're looking for>) & RetryCount < 5,
++RetryCount;
ErrMsg = LogCapture(<your SQL connection string>);
)