added has_connection to check for a valid DB connection; fixes #1264

if no connection was present, connection() would try to connect again,
causing the original exception to be lost.