简体   繁体   English

相同连接字符串的连接池,但来自 SQL 服务器中的不同主机/IP,ADO.NET

[英]Connection pooling for same connection string but from different hosts/IP in SQL Server, ADO.NET

I have explored the concept of connection pooling and Max Pool size for SQL Server and it says that for same connection string SQL Server will open the new connections in same pool.我已经探索了 SQL 服务器的连接池和最大池大小的概念,它说对于相同的连接字符串 SQL 服务器将在同一个池中打开新连接。

Now, we have two web servers and a load balancer directing requests to either of them.现在,我们有两个 web 服务器和一个将请求定向到其中任何一个的负载均衡器。 So, the connection string being used by the API from both the servers will be same.因此,来自两个服务器的 API 使用的连接字符串将是相同的。

My question is, will both the servers use the same pool to open new connections or will it open the new connections in different pools?我的问题是,这两个服务器会使用同一个池来打开新连接还是会在不同的池中打开新连接?

As the host_name is different for the sessions in sys.dm_exec_sessions table , my guess is it should use different pools but I couldn't find any article specifying the same.由于sys.dm_exec_sessions table中会话的 host_name 不同,我猜它应该使用不同的池,但我找不到任何指定相同的文章。

The connection pool is on the client, not the database server.连接池在客户端,而不是数据库服务器。 Each of your web servers has a separate connection pool per distinct connection string and security context.每个 web 服务器都有一个单独的连接池,每个不同的连接字符串和安全上下文。

This query will show the current number of database connections per host for all connection pools:此查询将显示所有连接池中每个主机的当前数据库连接数:

SELECT host_name, COUNT(*) AS connection_count
FROM sys.dm_exec_sessions
GROUP BY host_name;

Although there is no notion of connection pools on the server, you can get an estimate of connections per pool by aggregating on available connection string attributes:虽然服务器上没有连接池的概念,但您可以通过聚合可用的连接字符串属性来估计每个池的连接数:

SELECT host_name, program_name, host_process_id, client_interface_name, login_name, COUNT(*) AS connection_count
FROM sys.dm_exec_sessions
GROUP BY host_name, program_name, host_process_id, client_interface_name, login_name;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM