Tweaks to error handling and added auto reconnect.

Update error handling of system errors and automatically attempt to reconnect a connection if a previous query has failed.