Click here to Skip to main content
12,405,543 members (58,544 online)
Rate this:
 
Please Sign up or sign in to vote.
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 0: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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 9 Jun 2012
Copyright © CodeProject, 1999-2016
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