Moving DB connection into thread