Close database connections between writes; slower but more flexible