Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL2000 C#
I execute the large size of batch T-Sql('Some column add\some data type') to the direct sql Query analyzer & execute fine.
But when I run this query through coding, there is arise error msg.i.e.('time out expire & server not responding')
 
How will i solve above problem????
Please help me any instruction....
Posted 9-Jun-12 1:51am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This error is happening because your SQL command is taking longer than 30 seconds to execute. I would recommend using an asynchronous call to execute this command, since it is running that long. Further, I would recommend that the SQL code be put into a stored procedure so that it can be compiled and optimized, which will reduce how long it runs. However, the root issue is the command timeout when you run it via C#.
 
The solution is to change the SQLCommand objects CommandTimeout value from 30 (seconds) to whatever you need plus a buffer. Here is what the code would look like:
 
SqlCommand cmd = new SqlCommand("select * table1", connectionString);
cmd.CommandTimeout = 120;
 
Here is an article that talks about your error and shows how it can happen by replicating it:
 
http://blogs.msdn.com/b/spike/archive/2008/07/31/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation-or-the-server-is-not-responding.aspx[^]
 
In there, the author changes the timeout to ten seconds. You can use similar code, only change the timeout to be something that won't error like I did above.
  Permalink  
Comments
Sandeep Mewara at 10-Jun-12 1:54am
   
Good answer. 5!

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

  Print Answers RSS
0 OriginalGriff 400
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 245
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 9 Jun 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