Språk

SqlConnectionStringBuilder.IdleTimeout Property

Definition

Gets or sets the maximum time, in seconds, that a connection can sit unused (idle) in the connection pool before it is discarded. The default is 300 (5 minutes).

public:
 property int IdleTimeout { int get(); void set(int value); };
public int IdleTimeout { get; set; }
member this.IdleTimeout : int with get, set
Public Property IdleTimeout As Integer

Property Value

The idle timeout for pooled connections, in seconds.

Remarks

This property corresponds to the "Connection Idle Timeout" key within the connection string.

In versions where the AppContext switch Switch.Microsoft.Data.SqlClient.UseLegacyIdleTimeoutBehavior is enabled (the default), the driver preserves historical pooling behavior and does not enforce this setting. Set the switch to false to enable idle-timeout enforcement.

The driver makes a best effort to discard connections that have remained idle in the pool for longer than this value. The exact point in the connection lifecycle at which the check occurs is an implementation detail and may change over time. This protects callers from receiving connections that may have been silently closed by firewalls, load balancers, or server-side inactivity thresholds.

A value of zero (0) disables idle expiration; connections are kept in the pool indefinitely (subject to other expiry rules such as LoadBalanceTimeout).

Idle timeout operates independently of LoadBalanceTimeout. Whichever threshold is exceeded first causes the connection to be discarded.

Applies to