Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
2.40/5 (4 votes)
See more: , +
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
Comments
Siva Hyderabad 30-Nov-13 6:24am    
hi,wajans .. i got this same error..please help me..

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
 
Share this answer
 
Comments
wajans 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 7-Dec-12 2:59am    
thanks...
Member 11904649 15-Dec-15 22:19pm    
here what is myCommand.
Eduard Keilholz 16-Dec-15 3:07am    
The SQL Command you're about to execute
Check if you are running into network or database load issues whenever this timeout error occurs.
 
Share this answer
 
Comments
wajans 3-Feb-11 4:58am    
Exactly the thing I am thinking..But how to go with this random scenario.
safihur Rahuman 22-Jul-14 3:17am    
running in local database
As Mr.Eduard Keilholz says use
C#
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
 
Share this answer
 
Comments
Member 9520369 30-Oct-13 12:10pm    
hi
anurag9179 23-Jun-14 1:22am    
hi
<br />
<br />
Try below options, set command timeout parameter to 0. It will execute till the end. By default it will timeout in 30 secs.<br />
<br />
sqlComm.CommandTimeout = 0; <br />
Check the timeout in connection string, try setting it to max...<br />
<br />
data source=ServerName;initial catalog=DataBaseName;uid=ID;pwd=Password;Connect Timeout=120.<br />
<br />
 <br />
<br />
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.<br />
<br />
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 .<br />
<br />
 check all these possibilities<br />
 
Share this answer
 
Comments
Member 11553660 8-Jul-15 23:50pm    
Its Working .... Thank you
 
Share this answer
 
Comments
wajans 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 Chikkala 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.
Member 13089439 7-May-17 5:00am    
hi wajans
i have the same issue, i have live server on the same machine as the application, every thing going ok after 5-7 days it give timeout exception on the command and all goes wrong, how did you solve your issue, need little guidence
G_P_M 5-Nov-12 9:30am    
I'm also facing the same issue. Do you have the solution for this?
thatraja 5-Nov-13 7:54am    
Did you check those links fully? Follow everything with patience, you'll win.
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900