B
Brandon Potter
Hi,
I was trying to find the best way to go about managing a SqlConnection
object being used by a web service. In theory my thinking was that I would
create a shared class that would hold 1 SqlConnection, handle the connection
string and opening/closing of the connection, and expose the connection as a
read only property from the class for the callers that need to assign it to
SqlCommands.
I also thought, that in theory, calling
HttpContext.Current.Application.Lock() just before opening the connection
[then the callers create a command, assign the connection, run a
SqlDataReader against the command] and
HttpContext.Current.Application.UnLock() just after the connection is
closed, that it would prevent other users from triggering the web service to
throw a "There is already an open DataReader...." exception when being
accessed at the same time.
However, when the web service receives 10-15 hits/sec, the "There is already
an open DataReader..." exception is occasionally thrown. Can someone
enlighten me as to where my thinking was flawed? The grand plan was to try
and "hold" the other instances of the web service until the 1 connection
becomes available again, and I thought that's what Lock() and UnLock() did;
but now I am confused!
Thanks,
Brandon
I was trying to find the best way to go about managing a SqlConnection
object being used by a web service. In theory my thinking was that I would
create a shared class that would hold 1 SqlConnection, handle the connection
string and opening/closing of the connection, and expose the connection as a
read only property from the class for the callers that need to assign it to
SqlCommands.
I also thought, that in theory, calling
HttpContext.Current.Application.Lock() just before opening the connection
[then the callers create a command, assign the connection, run a
SqlDataReader against the command] and
HttpContext.Current.Application.UnLock() just after the connection is
closed, that it would prevent other users from triggering the web service to
throw a "There is already an open DataReader...." exception when being
accessed at the same time.
However, when the web service receives 10-15 hits/sec, the "There is already
an open DataReader..." exception is occasionally thrown. Can someone
enlighten me as to where my thinking was flawed? The grand plan was to try
and "hold" the other instances of the web service until the 1 connection
becomes available again, and I thought that's what Lock() and UnLock() did;
but now I am confused!
Thanks,
Brandon