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
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
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.
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: