zoukankan      html  css  js  c++  java
  • ADO.NET Connection Pooling at a Glance

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.80).aspx

    http://www.codeproject.com/Articles/17768/ADO-NET-Connection-Pooling-at-a-Glance

    The following table lists the valid names for connection pooling values within the ConnectionString. For more information, see Using Connection Pooling.

     

    Name

    Default

    Description

    Connection Lifetime

    0

    When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. This is useful in clustered configurations to force load balancing between a running server and a server just brought online.

    A value of zero (0) causes pooled connections to have the maximum connection timeout.

    Connection Reset

    'true'

    Determines whether the database connection is reset when being drawn from the pool. For SQL Server version 7.0, setting to false avoids making an additional server round trip when obtaining a connection, but you must realize that the connection state, such as database context, is not being reset.

    The connection pooler is not influenced by the ChangeDatabase method as long you do not set Connection Reset to false. As the connection comes out of the pool the connection is reset with the server moving back to the login time database. There are no new connections created or reauthentications. If you set Connection Reset to false, connections in the pool to different databases might result.

    Enlist

    'true'

    When true, the pooler automatically enlists the connection in the creation thread's current transaction context. Recognized values are truefalseyes, and no.

    Load Balance Timeout

    0

    The minimum time, in seconds, for the connection to live in the connection pool before being destroyed.

    Max Pool Size

    100

    The maximum number of connections allowed in the pool.

    Min Pool Size

    0

    The minimum number of connections allowed in the pool.

    Pooling

    'true'

    When true, the SQLConnection object is drawn from the appropriate pool, or if it is required, is created and added to the appropriate pool. Recognized values are truefalseyes, and no.

    When you are setting keyword or connection pooling values that require a Boolean value, you can use 'yes' instead of 'true', and 'no' instead of 'false'. Integer values are represented as strings.


    Controlling Connection Pool through Connection String

    Connection string plays a vital role in connection pooling. The handshake between ADO.NET and database server happens on the basis of this connection string only. Below is the table with important Connection pooling specific keywords of the connection strings with their description.

    Name Default Description
    Connection Lifetime 0 When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified byConnection Lifetime. A value of zero (0) causes pooled connections to have the maximum connection timeout.
    Connection Timeout 15 Maximum Time (in secs) to wait for a free connection from the pool
    Enlist 'true' When true, the pooler automatically enlists the connection in the creation thread's current transaction context. Recognized values aretruefalseyes, and no. Set Enlist = "false" to ensure that connection is not context specific.
    Max PoolSize 100 The maximum number of connections allowed in the pool.
    Min PoolSize 0 The minimum number of connections allowed in the pool.
    Pooling 'true' When true, the SQLConnection object is drawn from the appropriate pool, or if it is required, is created and added to the appropriate pool. Recognized values are truefalseyes, and no.
    Incr PoolSize 5 Controls the number of connections that are established when all the connections are used.
    Decr PoolSize 1 Controls the number of connections that are closed when an excessive amount of established connections are unused.

    * Some table contents are extracted from Microsoft MSDN Library for reference.

    Other than the above mentioned keywords, one important thing to note here. If you are using Integrated Security, then the connection pool is created for each user accessing the client system, whereas, when you use user id and password in the connection string, single connection pool is maintained across for the application. In the later case, each user can use the connections of the pool created and then released to the pool by other users. Thus using user id and password are recommended for better end user performance experience.

    Sample Connection String with Pooling Related Keywords

    The connection string with the pooling related keywords would look somewhat like this

    initial catalog=Northwind; Data Source=localhost; Connection Timeout=30; 
    User Id=MYUSER; Password=PASSWORD; Min Pool Size=20; Max Pool Size=200; 
    Incr Pool Size=10; Decr Pool Size=5;

    Simple Ways to View Connections in the Pool Created by ADO.NET

  • 相关阅读:
    NO12 useradd-passwd-uname-hostname命令-上传rz下载sz-批量部署- Linux用户相关操作
    NO11 SSH故障排查思路和netstat命令
    NO10 查看Linux操作系统-版本-内核-Linux分区
    NO9 Linux快捷键整理及最常用命令
    NO8 find结合sed查找替换企业案例多方法精讲&命令总结!
    NO7 利用三剑客awk-grep-sed-head-tail等7种方法实践
    python 对比图片相似度
    MonkeyRunner 实现自动点击截屏后与本地图库进行对比输出
    monkeyrunner对比屏幕局部图像.getSubImage()
    锤子便签的 monkeyrunner 测试脚本(转)
  • 原文地址:https://www.cnblogs.com/wucg/p/2383856.html
Copyright © 2011-2022 走看看