Exception handling in connectDB

Ensure that socket will be closed if we could not create db connection.