Changing SqlConnection timeout

后端 未结 10 2120
孤街浪徒
孤街浪徒 2020-12-25 09:22

I am trying to override the default SqlConnection timeout of 15 seconds and am getting an error saying that the

property or indexer cann

10条回答
  •  [愿得一人]
    2020-12-25 09:51

    You can set the timeout value in the connection string, but after you've connected it's read-only. You can read more at http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx

    As Anil implies, ConnectionTimeout may not be what you need; it controls how long the ADO driver will wait when establishing a new connection. Your usage seems to indicate a need to wait longer than normal for a particular SQL query to execute, and in that case Anil is exactly right; use CommandTimeout (which is R/W) to change the expected completion time for an individual SqlCommand.

提交回复
热议问题