Improvement to database connection logic

This fixes a race condition on the shared random state, and errors in initial sql.Open() calls due to bad nodes.