Today, I encountered a problem in executing a stored procedure. There is a stored procedure in the system, which takes a long time to execute. If a large number of users submit at the same time on the webpage, the transactions in the process will fail, resulting in processing errors.
The test modified the transaction level from read uncomitted to serializable. However, Errors still occur. The most likely cause is that the database resources are insufficient, cannot process multiple large-scale transactions at the same time. Since the database cannot solve the problemProgramStarting with, it is limited to full-order execution, so ...... Solve the problem. Post the method. Please advise.
Environment ASP. NET, database sqlserver 2005
CodeVery simple, as shown below
Code
Function runprocedure ()
{
If (Application [ " Lockobj " ] = Null ) Application [ " Lockobj " ] = New Object ();
Lock (Application [ " Lockobj " ])
{
// Exec sp
// Long wait, about 10 seconds
}
// Other Processing
}
In this way, no matter how many users enter at the same time, only one user can run the stored procedure to prevent errors. The only problem is that the user will wait a little longer ......
Please advise.