0

We have a WCF Data Service connecting to a SQL Server 2008 R2 database. When the service is trying to access data from the database the connection is getting timed out before the Connection Timeout value and the timeout exception is thrown.

This is the connection string:

Data Source=XXXX;Initial Catalog=XXXX;MultipleActiveResultSets=False;
Connection Timeout=80;Integrated Security=false;User ID=XXX;Password=XXX

In this connection string, even though we gave 80sec as the Connection Timeout, the connection gets timed out at around 700ms and throws below exception

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

This is happening on some queries only.

Any help is appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 4
    Does it time out upon opening the connection or upon executing a command over the connection? There are two types of timeouts: Connection Timeout and Command Timeout. The latter is set on the command. – PHeiberg Nov 15 '12 at 09:30

3 Answers3

3

It's not the ConnectionTimeout that causes the error; it's the CommandTimeout. See also this question.

Therefore, the solution is to set a higher value for CommandTimeout in case of more expensive queries.

Community
  • 1
  • 1
Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
0

This type of timeout can have three causes;

  1. There's a deadlock somewhere

  2. The database's statistics and/or query plan cache are incorrect

  3. The query is too complex and needs to be tuned

Taken from the following links

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated

try to optimise the query as mentioned here

Community
  • 1
  • 1
Thangamani Palanisamy
  • 5,152
  • 4
  • 32
  • 39
0

I had the same problem and google brought me here.

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

In my case, the mssql firewall port (default = 1433 TCP) was not yet open on the db server.

dabor
  • 127
  • 1
  • 3
  • 13