connects to a db and writes rows