Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server ADO.NET , +
Hi Experts,
I have a windows service running every minute and has many database operations to perform.
It runs perfectly for many days, sometimes it suddenly stops and throws this exception. Later when we start to debug it, the exceptions goes off, but if we don't debug, the exception continues to come. We are tired of this totally random scenario. Please assist us with this.
We are using sqlhelper.cs for database interaction.
"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
Best Regards,
Wajid Ahmed Ansari.
Posted 2-Feb-11 20:39pm
wajans666
Comments
SambasivaRaoG at 30-Nov-13 6:24am
   
hi,wajans .. i got this same error..please help me..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

By default the timeout of an SQL 'statement' is set to 30 seconds. If SQL Server takes more than 30 seconds to complete your task, you'll receive a timeout. You may want to set the timeout yourself. The timeout property is called CommandTimeout, it's a property of the SqlCommand object.
 
using (SqlCommand myCommand = new SqlCommand())
{
   // Set the new command timeout to 60 seconds
   // in stead of the default 30
   myCommand.CommandTimeout = 60; 
}
 
Good luck!
 
Eduard
  Permalink  
Comments
wajans at 3-Feb-11 4:59am
   
As I said befor the error is random, If its related to command or connenction than it should come every time I run the service but its working fine say for some 20 days then suddenly it throws the exception..really weird, dont know what to do..Thanks for your reply.
Arup Kumar Maity at 7-Dec-12 2:59am
   
thanks...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check if you are running into network or database load issues whenever this timeout error occurs.
  Permalink  
Comments
wajans at 3-Feb-11 4:58am
   
Exactly the thing I am thinking..But how to go with this random scenario.
safihur Rahuman at 22-Jul-14 3:17am
   
running in local database
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4


 
Try below options, set command timeout parameter to 0. It will execute till the end. By default it will timeout in 30 secs.
 
sqlComm.CommandTimeout = 0;
Check the timeout in connection string, try setting it to max...
 
data source=ServerName;initial catalog=DataBaseName;uid=ID;pwd=Password;Connect Timeout=120.
 

 
On the SQL Server also you can set timeout of a query. Check with SQL Server DBA's to know the Query time out set on servers.
 
On IIS also you have timeout setting. In IIS --> Website tab --> Connection time out box . Set the max timeout value (in secs) IIS should maintain idle connection .
 
check all these possibilities
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
wajans at 3-Feb-11 6:41am
   
It seems a DB problem, but i connected through Sql Management studio and iam able to do everything through it (Like querying,updating etc...), just through code is the problem.
 
The service is calling DB very frequently. Since three hours the service is responding well and no sign of DB overloads. Also it had been on for 20 days without rest and everything was well.
 
I will post the message if i get this exception again, i already cleared my logs before.
 
The additional insight into the problem is every method going to DB suffers the same exception. Like simple update statement running within a second now takes more than 30 seconds when this problem comes up.
 
So i got curious as whats the main issue.
 
Hope this helps to get hold of problem.
 
Sivarjun N at 5-Nov-13 7:52am
   
I am also facing same problem like this. In localhost and test server there is no exception like this. But in live server I am getting this exception "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
--> I am creating(inserting through stored procedure) 50 invoices at a time in this case successful.
--> if I create 100 invoices for suppose 5 times (500), no problem. 6th time I'm getting exception.
--> I am using sql server 2008 r2. in my local PC and test server there is no exception. In live server I am getting problem.
G_P_M at 5-Nov-12 9:30am
   
I'm also facing the same issue. Do you have the solution for this?
thatraja at 5-Nov-13 7:54am
   
Did you check those links fully? Follow everything with patience, you'll win.
Sivarjun N at 5-Nov-13 8:02am
   
In my local machine I didn't get any exception. I updated live server with local code recently now I am getting the problem.
thatraja at 5-Nov-13 8:07am
   
That's my old answer(when I was new to this site).
Check this answer Click, check it
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

make it less often to access database, make it into view if the query is complex, make the query more spesific and accurate, also add timeout for retrieve data, check timeout on webconfig. Hope this help
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

As Mr.Eduard Keilholz says use
using(SqlCommand myCommand = new SqlCommand())
{
   // Set the new command timeout to 60 seconds
   // in stead of the default 30
   myCommand.CommandTimeout = 60;
}
 
This is correct solution but before that you have to check whether you run infinite loop
This condition occur when you run infinite for/while loop or max no of line store procedure
  Permalink  
Comments
Member 9520369 at 30-Oct-13 12:10pm
   
hi
anurag9179 at 23-Jun-14 1:22am
   
hi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 392
1 OriginalGriff 370
2 CPallini 190
3 Abdul Samad KP 145
4 George Jonsson 119
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100