Fixed bug when db connection fails