Generally database connections are NOT thread safe, so doing inserts in parallel on the same connection like that is bound to cause trouble.
So I would say that yes, you would need to open and close the connection inside the Parallel.ForEach()
. You might want to benchmark that as well. I'm not entirely convinced that doing inserts in parallel like that with multiple database connections would be any faster than doing them in a regular loop on a single connection.