Database connection thread