"Bryce K. Nielsen" <(E-Mail Removed)> wrote in
news:#(E-Mail Removed):
>> This sounds like a race condition.
>>
>> Does your app have multiple threads calling this code?
>>
>
> Yes, each of these threads open a new connection, so you're
> probably right. Is there a thread-safe way to create a
> connection and have it properly pull from the connection pool?
Bryce,
What might do the trick is a thread-safe factory that ensures only
one thread at a time can construct a connection instance (untested):
public class SqlConnectionFactory
{
private static readonly object _lockObject = new object();
public static SqlConnection GetConnection(string connectionString)
{
lock(_lockObject)
{
return new SqlConnection(connectionString);
}
}
}
Also see Jon Skeet's excellent article on multithreading in .Net for
more info:
http://www.yoda.arachsys.com/csharp/threads/
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/