MultiThreading error: There is already an open DataReader associated with this Connection which must be closed first

后端 未结 2 1085
时光取名叫无心
时光取名叫无心 2021-01-12 21:39

I have a Parallel.Foreach loop

var options = new ParallelOptions();
options.MaxDegreeOfParallelism = 1;
Parallel.ForEach(urlTable.AsEnumerable(),drow =>
{         


        
相关标签:
2条回答
  • 2021-01-12 22:08

    The problem is that ADO.NET data providers generally do not allow for more than one open data reader at a time per connection. SQL Server has the concept of multiple active result sets (MARS), but as far as I know MySQL does not yet support it.

    You will probably need to specify a different connection other than MySQLProcessing.MySQLStatic.Connection. There is nothing stopping you from using more than one connection. The problem here is that connections are expensive resources so you are supposed to use them sparingly.

    0 讨论(0)
  • 2021-01-12 22:10

    You're using the same connection at the same time.

    Do you have several thread ? Because it seems that 2 threads use the same connection to concurrently make a call.

    0 讨论(0)
提交回复
热议问题