question

satya avatar image
satya asked

How to restrict the stored procedure calling twice on submit ?

Hi, Is there any approach in stored procedure code level to restrict the procedure to call twice on SUBMIT button. waiting for your valuable inputs.
t-sqlstored-procedures
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Usman Butt avatar image
Usman Butt answered
Prevention of user submitting twice should be handled at application level. This is the best way of doing it. I do not think handling it at database level would help your cause. You may end up with something undesired.
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
agree, the UI needs to handle this. the first step in the code needs to disable the button, then go on to make the request to the database. Logic in the database to recognise duplicate requests within NN (milli)seconds could also help but the UI needs to prevent the user causing the problem.
2 Likes 2 ·
Usman Butt avatar image Usman Butt commented ·
@Scot In that case It still smells like the web application OR application server being the culprit. Some serious Stress/Regression Testing with different option like very low network latency etc on application side needs to be done. Since I am sure there would be an/multiple application server/s being working as the middle-were, a check with NN milliseconds may still not be the best choice as it may cause some unwanted rollbacks.
1 Like 1 ·
Scot Hauder avatar image Scot Hauder commented ·
@Usman I've seen this during my years as a web developer. It isn't always the user clicking twice, some other weirdness happens that calls the stored proc twice. It is usually less than 10ms apart--too quick for consecutive clicks. This was especially concerning for us during credit card processing apps.
0 Likes 0 ·
Grant Fritchey avatar image
Grant Fritchey answered
You're saying that you want to execute the procedure two times? Then I would either execute it twice or just run the command within it two times.
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Hey @satya, I just looked, after 18 questions you've never accepted an answer on any of them. If someone has helped you out, please mark the question answered by clicking on the check box under the appropriate answer. It's just below the little thumbs down symbol.
1 Like 1 ·
satya avatar image satya commented ·
Thank you Grant, I don`t want to call it twice. If the user accidentally clicks twice on SUBMIT button, Stored Procedure calls twice. In this situation how to restrict the second call from db side.
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
That's different than what you asked. In this case, any data submitted should have a unique constraint on the table to prevent duplicate data from being entered. That's all you have to do. Clicking submit any number of times will cause the insert to fail.
0 Likes 0 ·
satya avatar image satya commented ·
Sorry @grant, till now i didn`t notice that one. I got answers for all my questions.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.