I
Ira Gladnick
If a timeout occurs on a SqlCommand while it is in the middle of
executing a transaction contained withing a stored procedure
(transaction is started in the stored procedure with BEGIN TRANS, as
opposed to being started in the .Net application), database resources
can stay locked even after the connection is closed when connection
pooling is enabled.
However, if SqlConnection.ClearPool is called prior to closing the
connection, then the connection is discarded (not returned to the
pool) when it is closed. This results in the transaction being rolled
back, freeing the database resources.
So it would seem that a 'best practice' would be to always call
SqlConnection.ClearPool whenver a command timeout occurs.
I haven't seen any discussion of this anywhere. Was wondering what
other people might think about doing an unconditional ClearPool under
these circumstances.
(It would be nice if there was some way to detect if there was an open
transaction on a connection, in the case where the transaction was
started from within a stored procedure, but don't believe this is the
case. That way, the ClearPool could be called only when there was
actually an open transaction that needed to be rolled back.)
executing a transaction contained withing a stored procedure
(transaction is started in the stored procedure with BEGIN TRANS, as
opposed to being started in the .Net application), database resources
can stay locked even after the connection is closed when connection
pooling is enabled.
However, if SqlConnection.ClearPool is called prior to closing the
connection, then the connection is discarded (not returned to the
pool) when it is closed. This results in the transaction being rolled
back, freeing the database resources.
So it would seem that a 'best practice' would be to always call
SqlConnection.ClearPool whenver a command timeout occurs.
I haven't seen any discussion of this anywhere. Was wondering what
other people might think about doing an unconditional ClearPool under
these circumstances.
(It would be nice if there was some way to detect if there was an open
transaction on a connection, in the case where the transaction was
started from within a stored procedure, but don't believe this is the
case. That way, the ClearPool could be called only when there was
actually an open transaction that needed to be rolled back.)