Say I have a webpage. In that webpage, I have a button with a click event listener. When I click on the button, it makes an ajax call(XMLHttpRequest) to update some values in server side database. My database query takes much time to complete and as a result, response also takes much time to come back to the client side(because the code is synchronous). And in the mean time, if I refresh my webpage, the ajax request gets cancelled and the update query also gets stopped.
I want to make it work in such a way that I will make the ajax call, and it will initiate the database query but it will not wait for it to complete. And even if, I refresh the page, the database query should not be cancelled out.
In the backend(server side), I have C# asp.net framework and sql server database.
So the ajax call goes to my server side code which is written in C# and from there I call a stored procedure that contains the long query.
I want that the ajax call will initiate this long query and will not wait for completion of the query. And even if I refresh the page, the query will not get cancelled out.(Ajax call may get cancelled out But the query should not stop running in my server)
What are ways available in C#, dapper, asp.net and sql server to implement this scenario?
If the query takes much time, you have a separate temp table for storing results from the query.
You create a stored procedure for the query and store the result from the query to the temp table with the username as a separate column.
You can initiate the stored procedure from the UI and you should be having a ajax method for retrieving the latest result from the temp table with respective to the particular user.
I hope you understood my explanation.
Have a separate table for initiating the stored procedure. Now you can use sqldependency for running the stored procedure in the background for every onChange notification. Please view this answer for sqldependency implementation.
I hope this helps