0

In the web API application, we use a repository pattern with the SQL server. we get the below connection error,

  1. There is already an open DataReader associated with this Command which must be closed first.
  2. Invalid operation. The connection is closed.
  3. ExecuteReader requires an open and available Connection. The connection's current state is connecting.

Is there a possibility to share a connection in a connection pool?

We open multiple connections at the same time

S. Deshmukh
  • 314
  • 4
  • 19
  • Pooled connections are reset when reused. These error suggest you may have different threads using the same connection. Are you rolling your own connection pool or using `static` modifier? – Dan Guzman Oct 23 '19 at 11:00
  • Thank you for replying, How I can find whether the different threads used the same connection? we are using dapper fo connection. Sorry but I can't understand this 'Are you rolling your own connection pool', we are using the Azure SQL server. We are not using static modifier. – S. Deshmukh Oct 23 '19 at 12:33
  • Is there any relation with MultipleActiveResultSets, because in our project we set it to true – S. Deshmukh Oct 23 '19 at 13:03
  • If I understand correctly you have created a connection pool by your self. SQL Server and .Net manage an internal connection pool which is efficient and thread-safe, so you do not need to create another connection pool. – Farhad Rahmanifard Nov 04 '19 at 13:40

1 Answers1

0

refer below link for MARS and reused connection https://www.designlimbo.com/multi-threading-entity-framework-and-mars/

'Because of MARS can improve performance when you have multiple concurrent operations trying to hit the database, the existing open connection is reused. '

S. Deshmukh
  • 314
  • 4
  • 19