Gracefully complete a long SQL Server query from ADO.NET

I am using an asynchronous process to extract data from a long SQL query. A process calls a stored procedure using a method SqlCommand.BeginExecuteReader().

Sometimes I would like to shut down my process and gracefully terminate any running requests.

After some testing, it seems enough to call SqlConnection.Close(). For good measure, I also explicitly call SqlConnection.Dispose().

When I run the trace through SQL Server Profiler, it looks like the query ends gracefully as I see it SQL:BatchStarting, and then SQL:BatchCompletedafter the call Close().

Can anyone confirm that you want to close the connection?

+5
source share
1 answer

Close , :

, , Close finally, .

SqlConnection.Close SqlConnection.Dispose, . Dispose IDisposable, SqlConnection.Close, , , :)

DataReader, , .

+2

All Articles