I'm getting a familiar Timeout SqlException when I add a lot of new records quickly using Subsonic ActiveRecord and Sql Server.
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
I have managed to replicate this issue with the following simple block of code:
for (int i = 0; i < 1000; i++)
{
var address = new Address();
address.City = "TEST";
address.Save();
}
The code will add records until it reaches 100 (the Max Pool Size, probably not coincidentally) at which point it fails out with the above exception. After that, the connections are held for 5-10 minutes or so during which time all attempts to use the database give the above exception.
Interestingly, I have found that running this on my local machine in VS (same codebase against the exact same database instance) the code succeeds in adding all 1000 records. Perhaps the latency between here and my host just slows the database calls down enough?
Given that it works locally I suppose this isn't a Subsonic issue directly, but is there some mistake I am making or any way I can change my code or configuration to handle the rapid opening and closing of connections that occurs when adding a lot of records serially?