Added sql error handling.