Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to avoid [System.Data.SqlClient.SqlException] = {"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not "}
when i will be update the SQL query update join query at time 1000 records in the database at every second. it will be shown this exception.
any one have idea about this exception
thanks in advance.

You can change SqlCommand.CommandTimeout[^] to are lager value then the default at 30 sec.
Share this answer
thatraja 20-Jun-11 10:40am    
You beat me to it man, 5!
Kim Togo 20-Jun-11 10:41am    
vrushali katkade 20-Jun-11 23:58pm    
i have already set SQLcommand.timeout=120
Kim Togo 21-Jun-11 2:19am    
Then perhaps the problem is else were. Please see Solution 3 from Dylan Morley.
Increase value for Timeout of your SQL Connection & SQL Command

For Connection in Web.Config,
<add key="ConnectionString" value="server=(local); uid=sa; password=sa; database=master;Connection Timeout=30" />

For Command,
public void CreateSqlCommand()
   SqlCommand cmd = new SqlCommand();
   cmd.CommandTimeout = 15;
   cmd.CommandType = CommandType.Text;

& also take a look at the following page.
Troubleshooting: Timeout expired[^]

Free attachment
DBA’s Quick Guide to Timeouts[^]
Share this answer
Kim Togo 20-Jun-11 10:42am    
And 5 to you. Changing in the connection string can be a better idea :-)
Increasing the command timeout will solve the problem, but you are addressing the issue rather than the cause

Default query timeout is 30 seconds, so assuming you haven't changed this your queries are taking 30 seconds to run and then reporting timeout.

Can you tune your queries at all?

* Are all tables included in the query correctly indexed. Clustered index on tables etc?
* Have you run your query through Execution Planner? Any areas that could be improved?
* Is only the data you need to update being updated?

You should definitely have a look at the source of the problem first and see if you can improve things here.
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