Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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

1 solution

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:

C#
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.
 
Share this answer
 
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)



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