Maybe SQLGetMessage?
Haven't tested it, but looks to be, what you are looking for.