Improve error handling routine in DB connection and file upload process