Script to check SQL Server connection pooling
Our applications are using a high number of connections and the server is very busy. How do I check whether the application is using connection pooling correctly when connecting to SQL Server? Is there an easy way to see which connections are using connection pooling and which ones are not? In this tip, I will go over how to capture this information for each logon, so you can see which connections are taking advantage of connection polling.
SQL Server 2005 introduced DDL Triggers and this solution takes advantage of the DDL Logon trigger along with the EVENTDATA() function to determine if the connections are using connection pool or NOT.
Identifying this fact is very important to every DBA as the cost of opening a connection every time data is requested is expensive. The cost of each user connection is approximately (3 * network_packet_size + 94 KB) where the default network packet size is 4 KB. That means each user connection cost is approximately 130 KB. In addition, the time it takes to make the connection can also slow down processing.
Here is the script to create a table to store the data and a DDL Logon trigger to capture this data. This should be created in the master database.
In order for users to write to this table, that do not have rights to this table, I am using the EXECUTE AS clause in the trigger to run the code using the equivalent of the "sa" account. If you do not want to use the "sa" account another option is to create a new login, grant insert permissions to this table for this login and then use this login in the EXECUTE AS clause in the trigger.
Here is another way to do this by giving GRANT INSERT permissions to PUBLIC for table master.dbo.ServerLogonHistory.
Here is a sample result from the data that was collected using the above DDL trigger.
You can look at the IsPooled column to check if the connections are pooled.
- 1 = pooled and
- 0 = non-pooled connections.
- Here is another approach for finding connection pool information by James Rowland-Jones
- Take a look at these other DDL Triggers
- Keep on eye on this audit table, because this will track all connections to your database server and may get quite large.
- If you have any issues with LOGON triggers and you can not connect to SQL Server review this tip
About the author
View all my tips
Article Last Updated: 2009-09-04