Executing a time consuming stored procedure on ASP.NET 2.0 + Sql Server 2008
In one part of our application, we have to save som开发者_运维知识库e data. The saving of data takes some time and it could vary from few secs to few minutes. To handle this, so there isn't a sql time out we have following process in place.
Note: This is all setup by our DBA and this process is in use for several years without any problem.
1: Call a storedProcedure that places a job in a table. This stored procedure returns me a jobid. The input parameters to this sp is an exec statement to execute another storedprocdure with parameters.
2: Then I call another stored procedure passing the jobid, that will return the status of the job e.g. completed(true) else false + an error message.
3: I loop through step 2 for max 5 times with a sleep of 2 seconds. If the status returned is completed or there is some error, I break out of the loop. And after 5 times still the status in incomplete, I just display message that it's taking too long and please visit the page later (this isn't a good idea but so far the process has finished in about 2-3 times looping and not reached 5 times max but there are chances).
Now I am wondering if there is any better way to do the above job or even today, after several years, this is the best option I have?
Note: Using ASP.NET 2.0 Webforms / ADO.NET
I would look into queueing the operation, or if that's not an option (sounds like it might not be) then I would execute the stored procedure asynchronously, and use a callback to let you know when it's finished.
This question might help:
Ping to stored procedure to know execution completed in .net?
精彩评论