I was asked to take over an application, which was running fine under 1-2 users testing it, but once we put it through a larger test, it started crashing. We’re seeing random timeouts, along with messages about the code not being able to find certain columns that it expected to be there to bind to, though with just 1-2 users it was working.
The structure of the application is:
--------------
| WebSite |
--------------
| WebService |
--------------
| Database |
--------------
The website does all communication with the database via the webservice. Looking through the webservice code, I saw it was using a class to do the database work, and had this declared as a class level variable:
private static SqlConnection cn;
This was then being used in all the methods on the page that would need a connection. Being static, this mean there is just one instance for all users correct? I just want to confirm I’m seeing it correctly, as we removed it and are testing it now. Seeing that line to me means that 1 instance of the connection object was being shared amongst all users, which would explain why it was okay for 1-2 users, but the larger the number of users, the more people were queued waiting for it, eventually leading to the random errors. Just want to confirm I’m understanding this correctly.
Thanks.
Yes that static variable will be accessed across users. The real root of the problem is the lack of thread safety though, not necessarily the sharing of a connection object.