M
Mike Williams
For some days now we have been trying to get to the bottom of an issue with
a simplified version of our real application. In brief we have a Master
object within a main AppDomain which is responsible for spawning a Slave MBR
object in a newly created AppDomain upon request. When the Slave finishes
its work, it informs the Master (using a standard remoting MBR call on a
shared interface) and the Master begins the process of spawning a new Slave
and tearing down the AppDomain of the previous slave.
So far as the description stands above, all is well and the Slave object and
its hosting AppDomain are unloaded gracefully. However, if we create a
SqlConnection object (in either Master or Slave AppDomain) and simply Open
it then Close it immediately (never even bothering to read/write any data),
the above AppDomain unloading stops working and we start to build up a
number of AppDomains trying to be unloaded. To solve this situation, we have
found that if we explicitly turn off the Sql Managed Provider's connection
pooling (using Pooling=False in the connection string) then it goes back to
working again.
Why we are puzzled though is this: Does the SqlConnection Pool hold onto
some unmanaged resources/code which, whatever AppDomain it is created in
(implicitly by creating a SqlConnection object), any AppDomain cannot be
unloaded as the unmanaged resources/code do not actually belong to the
AppDomain, but to the overall Process?
Clearly we can get round the problem at the cost of some performance by
turning Connection Pooling off, but we would like to know whether this is
our only option.
Thanks in advance
Mike
a simplified version of our real application. In brief we have a Master
object within a main AppDomain which is responsible for spawning a Slave MBR
object in a newly created AppDomain upon request. When the Slave finishes
its work, it informs the Master (using a standard remoting MBR call on a
shared interface) and the Master begins the process of spawning a new Slave
and tearing down the AppDomain of the previous slave.
So far as the description stands above, all is well and the Slave object and
its hosting AppDomain are unloaded gracefully. However, if we create a
SqlConnection object (in either Master or Slave AppDomain) and simply Open
it then Close it immediately (never even bothering to read/write any data),
the above AppDomain unloading stops working and we start to build up a
number of AppDomains trying to be unloaded. To solve this situation, we have
found that if we explicitly turn off the Sql Managed Provider's connection
pooling (using Pooling=False in the connection string) then it goes back to
working again.
Why we are puzzled though is this: Does the SqlConnection Pool hold onto
some unmanaged resources/code which, whatever AppDomain it is created in
(implicitly by creating a SqlConnection object), any AppDomain cannot be
unloaded as the unmanaged resources/code do not actually belong to the
AppDomain, but to the overall Process?
Clearly we can get round the problem at the cost of some performance by
turning Connection Pooling off, but we would like to know whether this is
our only option.
Thanks in advance
Mike