2

I know ADO.NET creates a pool in memory when you establish a connection with database. I know when we close the connection or dispose the connection it is not removed from the memory. As long as connection string is same the connection will be taken from the connection pool. I have two question related this:

  1. When this connection pool will be released form memory?
  2. I heard that ADO.NET doesn't use connection pooling in case of distributed transaction (transaction scope). Is it true or false?
Umer Waheed
  • 4,044
  • 7
  • 41
  • 62

1 Answers1

2

1) The connection pooler removes a connection from the pool after it has been idle for approximately 4-8 minutes. Also ADO.NET 2.0 has two new methods to clear the pool: ClearAllPools and ClearPool. ClearAllPools clears the connection pools for a given provider, and ClearPool clears the connection pool that is associated with a specific connection.

2) Its true.

For information, you need to enlist a transaction that was started after the connection was opened, you can enlist in an existing distributed transaction using the EnlistTransaction method of the DbConnection object for the provider you are working with. Enlisting in an existing distributed transaction ensures that, if the transaction is committed or rolled back, modifications made by the code at the data source will be committed or rolled back as well.

orhun.begendi
  • 937
  • 3
  • 16
  • 31
  • Thanks @orhun for answer. Can we set any time value to remove connection pools > – Umer Waheed Mar 21 '17 at 07:13
  • in practice yes you can. But many ways to clear your connection. As i mentioned you can call ClearPool method, also (best way to handle) you can use "using" for every action so you can dispose every connection. Also there is a topic for this, you can check it out. http://stackoverflow.com/questions/2748706/connection-timeout-and-connection-lifetime – orhun.begendi Mar 21 '17 at 07:23
  • 2) Its true. Do you mean it is true only when TransactionScope is using MS-DTC, and false if it is not escalating to MS-DTC, right? – Zeshan Munir Mar 28 '17 at 12:52