0

I got the error

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

during the command execution.

I also set Connect Timeout=60 in the connection string.

That stored procedure execution time is around 35 seconds.

Connection is established, but result is not returned.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Elango Sengottaiyan
  • 166
  • 1
  • 2
  • 13
  • 1
    https://stackoverflow.com/questions/847264/what-is-the-difference-between-sqlcommand-commandtimeout-and-sqlconnection-conne – Sarvesh Mishra Feb 08 '19 at 06:16
  • 1
    Possible duplicate of [What is the difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout?](https://stackoverflow.com/questions/847264/what-is-the-difference-between-sqlcommand-commandtimeout-and-sqlconnection-conne) – Stefan Becker Feb 08 '19 at 06:24
  • Have you thought whether it is possible to optimise your stored procedure? – Steve Ford Feb 08 '19 at 09:20

2 Answers2

7

DbCommand has CommandTimeout, which is what you want here - it is set per command; the "connect timeout" only impacts, reasonably enough, what the timeout is for connecting. The default value for CommandTimeout on SqlCommand is 30 seconds.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
0

You can also extend connection timeout in connectionstring

;Connection Timeout=30

See: Connection timeout for SQL server

VoonArt
  • 884
  • 1
  • 7
  • 21
  • that is the timeout for *connecting*, not for *executing*. You cannot set the execution timeout in the connectionstring – Hans Kesting May 03 '23 at 10:16