Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cancel a database query in ASP.NET when the user's browser disconnects?

My ASP.NET (3.5) app allows users to run some complex queries that can take up to 4 minutes to return results.

When I'm doing a long loops of code, I'll check Response.IsClientConnected() occasionally so I can end the page if the user closes their browser or hits the stop button.

But when querying SQL Server, my .NET code is blocked at the call to GetDataReader().

Is there a straightforward way to do GetDataReader() asynchronously so I can wait around for it but still check, say, every 5-10 seconds to see if the user is still connected, and bail on the database query if they've left?

Or is there some other alternative I'm not thinking of?

like image 706
richardtallent Avatar asked Mar 05 '10 19:03

richardtallent


People also ask

Which of the following is used to open a table in a database in asp net?

Displaying Data from a Database. Once you've got a database with data in it, you can display the data in an ASP.NET web page. To select the table rows to display, you use a SQL statement, which is a command that you pass to the database.


1 Answers

you can use the sqlcommand's BeginExecuteReader to get an asynch sqlreader example

not 100% sure if thats what you need?

link showing cancel

like image 129
Pharabus Avatar answered Oct 15 '22 06:10

Pharabus