-2

Why below error comes?

System.Data.SqlClient.SqlException Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

Novarg
  • 7,390
  • 3
  • 38
  • 74
  • Increase the `Timeout` – Thirisangu Ramanathan Dec 12 '14 at 06:51
  • 2
    A simple Google search will let you know that! – Rahul Singh Dec 12 '14 at 06:52
  • possible duplicate of [Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated](http://stackoverflow.com/questions/8602395/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation) – Rahul Singh Dec 12 '14 at 06:56
  • http://stackoverflow.com/questions/16917107/occasionally-getting-sqlexception-timeout-expired Above post is already answer your question I think. – Ye Win Dec 12 '14 at 07:08

2 Answers2

2

You should normally try to write fast sql (<100ms) otherwise your application will be sluggish for the end users.

If your server reply in time when you send the request manually, There may be a read lock on a table and the second query keep on waiting for the read lock to end before processing.

In that case try to add WITH(NOLOCK) or WITH(READUNCOMMITTED) to your select statement.

David Doumèche
  • 508
  • 3
  • 10
0

Acccording to your situation and err msg, I think it may be caused by mainly two reasons:

Long running tasks:In default SQL Connection will wait for 30 seconds, but over this time, if you still cannot connect to the db, the kind of error will be thrown out.

For the second reason, that there might be an uncommitted transaction.

Of course, you should Close Connnection at a time when you don't want to use it (using…… statement is recommanded)

See more about this kind of issue, you can refer to:

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

Jilu
  • 67
  • 1
  • 2
  • 12