I think the recursive idea is a bad idea,
it can simply blow the stack, if the pool size
was lets say 1000, you would make a 1000 retries
recursively, dont' you think that perhaps
a while loop would solve this issue in a much
cleaner and faster way?
Also in regards to keeping a connection
static in asp.net that would also be a very
bad idea, when multiple datareaders or writers
are trying to access the same connection pool;
it will periodically throw exceptions of
datareader or writer already in use.
I made the fatal mistake of creation my ConnectionManager within my table access classes
static and if two clients using my asp.net application where lets say doing a search
the datareader would get used by the first one
and an exception will be thrown for the second.
Microsoft recommends creating a new SqlConnection
for every io; this realistically wont' be a problem considering it will all be pooled at the end.
Yes the recursive idea is bad. Especially as written in the sample code.
First the num_tries counter never gets incremented as the recursion progresses.
Secondly, suppose max_tries is 100. And it takes 50 tries to find a working connection. Once this happens, the ExecuteDataReader will recursively re-execute 50 times as it ripples up the stack.
Too bad the author didn't understand recursion or test his code
First the num_tries counter never gets incremented as the recursion progresses.
Secondly, suppose max_tries is 100. And it takes 50 tries to find a working connection. Once this happens, the ExecuteDataReader will recursively re-execute 50 times as it ripples up the stack.
Too bad the author didn't understand recursion or test his code