finished database connection logic