Initial DB connection logic and queries