Can I use Parallel.For with sql Commands?

前端 未结 2 1952
别那么骄傲
别那么骄傲 2020-12-17 05:25

I have a class of range

public class avl_range
{
    public long start { get; set; }
    public long end { get; set; }
}

If I use a normal

2条回答
  •  佛祖请我去吃肉
    2020-12-17 05:55

    An Npgsql connection can't be used concurrently - only one command may be running at any given point in time (in other words, no MARS support).

    It may definitely make sense to open multiple connections to perform your queries in parallel. Although establishing a new physical connection is expensive, connection pooling is extremely lightweight, so there's very little overhead in reusing physical connections. The main reason not to do this is if you need your multiple operations to be in the same transaction.

提交回复
热议问题