Click here to Skip to main content
13,142,622 members (53,861 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
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:[^]

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.
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 |
Web02 | 2.8.170915.1 | Last Updated 9 Jun 2012
Copyright © CodeProject, 1999-2017
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