Improve database error
(cherry picked from commit fd68e6b)