Improve resiliency of dedicated database against network issues.

- For a dedicated database connection (i.e., the main query
  connection), force a ping packet through after each failed query
  before allowing a new query to proceed without a reconnect.  If
  the ping fails, force a reconnect.

  Additionally, also force a connection ping if it has been more
  than 5 minutes since the last successful query or ping before a
  query is allowed through (if this fails, a reconnect is forced).

- No changes are made to the behavior for connection pooled MySQL
  connections.