When a connection is first opened, a connection pool is created based on an exact matching algorithm that associates the pool with the connection string in the connection. Subsequent failures after a blocking period ends will result in a new blocking periods that is twice as long as the previous blocking period, up to a maximum of one minute. If the application attempts to connect within the blocking period, the first exception will be thrown again. When connection pooling is enabled, and if a timeout error or other login error occurs, an exception will be thrown and subsequent connection attempts will fail for the next five seconds, the "blocking period". For more information, see "Controlling Connection Pooling with Connection String Keywords" later in this topic. You can also supply several connection string modifiers to control connection pooling behavior. Unless you explicitly disable it, the pooler optimizes the connections as they are opened and closed in your application. By default, connection pooling is enabled in ADO.NET. Pooling connections can significantly enhance the performance and scalability of your application.
Different instances of SqlCredential will use different connection pools, even if the user ID and password are the same. When using ChangePassword, the SqlCredential instance affects the connection pool. Connections are also pooled based on whether they are enlisted in a transaction.
Connections are separated into pools by connection string, and by Windows identity when integrated security is used. ADO.NET keeps several pools at the same time, one for each configuration. Only connections with the same configuration can be pooled. Once the connection is returned to the pool, it is ready to be reused on the next Open call. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. If a pooled connection is available, it returns it to the caller instead of opening a new connection. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. It manages connections by keeping alive a set of active connections for each given connection configuration. The pooler maintains ownership of the physical connection. To minimize the cost of opening connections, ADO.NET uses an optimization technique called connection pooling.Ĭonnection pooling reduces the number of times that new connections must be opened. This means that during application execution, many identical connections will be repeatedly opened and closed. In practice, most applications use only one or a few different configurations for connections. A physical channel such as a socket or a named pipe must be established, the initial handshake with the server must occur, the connection string information must be parsed, the connection must be authenticated by the server, checks must be run for enlisting in the current transaction, and so on. Connecting to a database server typically consists of several time-consuming steps.