473,509 Members | 12,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stopping a Long Running Query

How do you stop a long running query with a SQLConnection or SQLCommand?

Calling Close on either just waits until the query is done. Is there a way
to stop it?
The following on a long query
SqlConnection mySqlConnection = new
SqlConnection("server=(local)\\NetSDK;Trusted_Conn ection=yes;database=northw
ind");
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("select * from employees order by
EmployeeID", mySqlConnection);

SqlDataReader myReader = mySqlCommand.ExecuteReader();

myReader.Close();

mySqlConnection.Close();


Nov 15 '05 #1
4 5349
If you know the duration of time that defines 'long running' you cna set the
CommandTimeout property to that number + 1.

Before you do this though, make sure it's not the connection that's causing
the delay or the sheer number of records.

HTH,

Bill
"Kory" <ko**@removeme-mlsc.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
How do you stop a long running query with a SQLConnection or SQLCommand?

Calling Close on either just waits until the query is done. Is there a way
to stop it?
The following on a long query
SqlConnection mySqlConnection = new
SqlConnection("server=(local)\\NetSDK;Trusted_Conn ection=yes;database=northw ind");
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("select * from employees order by
EmployeeID", mySqlConnection);

SqlDataReader myReader = mySqlCommand.ExecuteReader();

myReader.Close();

mySqlConnection.Close();

Nov 15 '05 #2
The timeout isn't adequate because the record set can vary dramatically from
2-3 million records to 70-80 million, so it could run either for a minute or
3 hours...

Think of it as the ability to cancel a query. Right now, if you close it,
It waits there until the query is done.

There has to be (or sure should be ) a way to cancel a running query..
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If you know the duration of time that defines 'long running' you cna set the CommandTimeout property to that number + 1.

Before you do this though, make sure it's not the connection that's causing the delay or the sheer number of records.

HTH,

Bill
"Kory" <ko**@removeme-mlsc.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
How do you stop a long running query with a SQLConnection or SQLCommand?

Calling Close on either just waits until the query is done. Is there a way to stop it?
The following on a long query
SqlConnection mySqlConnection = new

SqlConnection("server=(local)\\NetSDK;Trusted_Conn ection=yes;database=northw
ind");
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("select * from employees order by EmployeeID", mySqlConnection);

SqlDataReader myReader = mySqlCommand.ExecuteReader();

myReader.Close();

mySqlConnection.Close();


Nov 15 '05 #3
Noone has ever had to cancel a running query?

"Kory" <ko**@removeme-mlsc.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
The timeout isn't adequate because the record set can vary dramatically from 2-3 million records to 70-80 million, so it could run either for a minute or 3 hours...

Think of it as the ability to cancel a query. Right now, if you close it,
It waits there until the query is done.

There has to be (or sure should be ) a way to cancel a running query..
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If you know the duration of time that defines 'long running' you cna set the
CommandTimeout property to that number + 1.

Before you do this though, make sure it's not the connection that's

causing
the delay or the sheer number of records.

HTH,

Bill
"Kory" <ko**@removeme-mlsc.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
How do you stop a long running query with a SQLConnection or SQLCommand?
Calling Close on either just waits until the query is done. Is there a way to stop it?
The following on a long query
SqlConnection mySqlConnection = new

SqlConnection("server=(local)\\NetSDK;Trusted_Conn ection=yes;database=northw
ind");
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("select * from employees
order by EmployeeID", mySqlConnection);

SqlDataReader myReader = mySqlCommand.ExecuteReader();

myReader.Close();

mySqlConnection.Close();



Nov 15 '05 #4
Kory wrote:
Noone has ever had to cancel a running query?

"Kory" <ko**@removeme-mlsc.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
The timeout isn't adequate because the record set can vary dramatically


from
2-3 million records to 70-80 million, so it could run either for a minute


or
3 hours...

Think of it as the ability to cancel a query. Right now, if you close it,
It waits there until the query is done.

There has to be (or sure should be ) a way to cancel a running query..
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl.. .
If you know the duration of time that defines 'long running' you cna set


the
CommandTimeout property to that number + 1.

Before you do this though, make sure it's not the connection that's


causing
the delay or the sheer number of records.

HTH,

Bill
"Kory" <ko**@removeme-mlsc.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...

How do you stop a long running query with a SQLConnection or
SQLCommand?
Calling Close on either just waits until the query is done. Is there a


way
to stop it?
The following on a long query
SqlConnection mySqlConnection = new

SqlConnection("server=(local)\\NetSDK;Trusted_Conn ection=yes;database=northw
ind");
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("select * from employees


order
by
EmployeeID", mySqlConnection);

SqlDataReader myReader = mySqlCommand.ExecuteReader();

myReader.Close();

mySqlConnection.Close();




I am probably confused. but, SQLCommand.Cancel() does not suffice? ...
--
Girish Bharadwaj

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
18168
by: Karaoke Prince | last post by:
Hi There, I have an update statement to update a field of a table (~15,000,000 records). It took me around 3 hours to finish 2 weeks ago. After that no one touched the server and no...
4
3345
by: Gary | last post by:
I am having a problem executing long running queries from an ASP application which connects to SQL Server 2000. Basically, I have batches of queries that are run using ADO in a loop written in...
0
1104
by: 2G | last post by:
Hi I'm trying to safely stop a thread but as you might have guessed, I'm failing at it. GetCurrentThread seems to get the wrong handle, my form disappears when I try to stop the thread and it...
5
17367
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an...
1
3455
by: Aaron West | last post by:
Try this script to see what queries are taking over a second. To get some real output, you need a long-running query. Here's one (estimated to take over an hour): PRINT GETDATE() select...
4
2034
by: bjm | last post by:
I am writing a program that will automate a series of application installations. I want to give the user the option of stopping the program's execution in between installations (for example, give...
0
1341
by: Prabhakar78 | last post by:
How to tune long running query?Please any one can provide me the steps to tune long running query in DB2 V9.1.0 and the environment is AIX (OS)
10
7502
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on...
2
3336
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.