Handling errors in connecting the database.

Retry on an exception in initializing the database.
Also cleaned up some of the messages in handling exceptions.