Added debug stacktrace to track down hard-to recognize conditions where the database connection in the current thread is undefined.