473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cancelling SQL Command forcibly / Command timeout

19 New Member
I have an Oracle stored procedure that takes approx 3 minutes to execute and I am using .net 2.0 data access provider for oracle. Now i want to cancel the execution of stored procedure from .net after few seconds, the code i wrote for this is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. //Start main function
  3.  
  4. System.Data.OracleClient.OracleDataAdapter objAdapter;
  5. System.Data.OracleClient.OracleConnection con;
  6. System.Threading.Timer objTimer = null;
  7.  
  8. if (!this.makeConnection(ref con, ref strExcpConn))
  9.     {
  10.                 throw new ExceptionBRE(strExcpConn);
  11. }
  12.  
  13. objTimer = new System.Threading.Timer(new System.Threading.TimerCallback(TimeClick),con, 5000, 5050);
  14. objAdapter.Fill(objDataTable);
  15.  
  16. cmd.Connection.Close();
  17.  
  18.                 strB = BuildCommaSep(ref objDataTable);
  19.                 return strB.ToString();
  20.             }
  21.             catch (Exception ex)
  22.             {
  23.                 if (_iFlag == 1)
  24.                 {
  25.                     throw new Exception("Process kill by timer");
  26.                 }
  27.                 else
  28.                     throw ex;
  29.  
  30.             }
  31.             finally
  32.             {
  33.                 objTimer.Dispose();
  34.                 _iFlag = 0;
  35.  
  36.                 if (con != null && con.State != ConnectionState.Closed)
  37.                 {
  38.                     con.Close();
  39.                     con.Dispose();
  40.                 }
  41.             }
  42.         }
  43. //End main function
  44.  
  45.  
  46. //Timer callback function
  47.         //Closes and disposes OracleConnection object
  48.         //If command is still executing then OracleConnection.Close() will result in an exception
  49.         private void TimeClick(object state)
  50.         {
  51.             _iFlag = 1;
  52.  
  53.             System.Data.OracleClient.OracleConnection objConn = (System.Data.OracleClient.OracleConnection)state;
  54.             if (objConn != null && objConn.State != ConnectionState.Closed)
  55.             {
  56.                 objConn.Close();
  57.                 objConn.Dispose();
  58.             }
  59.         }
  60.  
Working of above code is that: Forcibly cancel running SQL Command if it doesn't reply in specified time by Closing the connection to database and throw custom exception message (using _iFlag variable).

Though it's throwing the correct exception but after the command executes completely. i.e. Timer is set to 5 secs to kill a procedure that takes ~3 mins but i get response that process kill by time after 3 mins, can any one tell me why?

Or is there any better of doing this?
Thanks in advance
Mar 8 '08 #1
4 3750
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Why dont you set the "CommandTimeOut " property...

Dim TCmd As New OleDbCommand
TCmd.CommandTim eout = 20 'In Seconds

Once execution starts, After waiting for 20 seconds, if there is no result, it is terminated and an error is Generated..

REgards
Veena
Mar 8 '08 #2
kenobewan
4,871 Recognized Expert Specialist
In my mind it may not be cancelling the request that is the problem here. If this was my application, I would spend time more redesigning/optimizing my stored procedures.
Mar 8 '08 #3
enggwaqas
19 New Member
Hi,

Why dont you set the "CommandTimeOut " property...

Dim TCmd As New OleDbCommand
TCmd.CommandTim eout = 20 'In Seconds

Once execution starts, After waiting for 20 seconds, if there is no result, it is terminated and an error is Generated..

REgards
Veena
Data access provider for oracle from MS and ODP.NET 9.xxx doesn't support CommandTimeOut property.
Mar 9 '08 #4
Emmet M
1 New Member
Hi,

I have got the same problem with my application recently, and I had to create the helper for defeasible asynchronous oracle database operations.
http://www.codeproject.com/script/Ar...spx?aid=325884
Feb 8 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11531
by: Cath B | last post by:
I am pretty sure I am getting a command timeout when execute a SQL procedure that has an output parameter. The code below is in an asp page that is called using RSGetASPObject. I want to be able to send a message back to the calling page to indicate that a timeout has occurred, but am having a hard time capturing the timeout error. I intend to set the timeout parameters so that I don't get timeout errors, but in the case that I would I...
3
2490
by: rh0dium | last post by:
Hi all, Another newbie question. So you can't use signals on threads but you can use select. The reason I want to do this in the first place it I need a timeout. Fundamentally I want to run a command on another machine, but I need a timeout. I have to do this to a LOT of machines ( > 3000 ) and threading becomes necessary for timeliess. So I created a function which works with signals ( until you throw threading at it.. ) but I...
0
2393
by: Mike | last post by:
VB .NET 2003, Pocket PC 2003, CF 1.0 SP 2 Only when I use a proxy server, I'm getting this error when attempting to write data to a Stream object from an HTTPWebRequest object. (System.IO.Stream.Write() raises the exception):"An existing connection was forcibly closed by the remote host". The error only happens with fairly large amounts of data (around 24,500 bytes). Here is ToString() of the exception object raised:
2
3364
by: twigster | last post by:
Hi, I need to display in real time the output of a command line tool in a GUI written so far with Tkinter and Pmw. I've got a command line tool that I want to integrate to a GUI. The parameters are set using the GUI and a button executes the command. The calc is long so I need to see how fast it goes. This is given by the stdout... any idea how to do this?
0
1205
by: Sanjay T | last post by:
Hi, We are using ASP.Net 2005 and SQL Server 2005. We are storing sessions in the database. From time to time we get the following exception in the application while the ASP.Net session tries accessing the database. This also happens from time to time when our application is accessing the database. To make the posting brief, I am just putting part of the exception. Any ideas why this might be happening? Our web application is behind F5...
4
3295
by: Vicente García | last post by:
Hello!! sorry for my english, I've made an application that ran correctly for 3 days, It's a service, however in the third day the application failed because of "An existing connection was forcibly closed by the remote host" exception, and then the CPU usage was 95 %. I don't know why it happens :( The service is always runs and other application works with the service using sockets, the exception occur when the service tried to send a...
2
7958
by: John Kotuby | last post by:
Hi all, I have set up a page with a Repeater and a SQLDatasource control, the data control suggested by online Help for use with the Repeater. I am getting Timeout Expired after 30 seconds. I expect many of my queries to take longer than 30 seconds because they are ad hoc user-defined searches through multiple joined tables and associated Text fields. I have to learn more about creating full text indexes for searching...but. How can I...
2
10018
by: Gil_H | last post by:
Hi, I'm trying to run a script over unix on a remote machine. In order to automate it, the procedure requests the following: 1. Using SSH connection. 2. Operating a command on the remote machine. 3. Expecting password or (yes/no) request and authorize it. I get an error (I thing that it occures at the last part (3) of the password request).
1
1603
by: priravi | last post by:
Hi, I have a connection timeout of 400 and command timeout of 0 for a stored procedure . the stored procedure retrieves a long data and store it in dataset. I'm getting the "System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." exception thrown on that stored procedure ... any ideas why it may happen . i'm using execute dataset
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7359
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2754
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 we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.