I have written a c# multithread function that reads data from sqlserver and for each row of data starts a separate thread.In each thread I have codes that need to work with db. this is what I do in each thread:
- Create a new sql connection
- Connect to it and open it
- Do work
- Close connection (while it is not necessary)
I should note that I use Using() command and I have read that this statement manages sql connection and closes it automatically after command is executed.
this function should be called periodically (say every 1 minute) and this is the problem i get into:
after first call number of active sql connections increases to number of rows (Threads that created per each row).in the second call this number increases again. for example after 5 calls with 100 rows we have 500 active sql connections! but I have read that connection pooling manages connections and uses created connections again. what should i do to solve this problem? did I miss any statement or is there something to do that I forgot?