1

During app loading a single user will add 10 connections to the pool. Then if I load another user I will have a total of 20 connections.

Why are new connections being added to the pool instead of reusing connections? I can see that that there are connections available that haven't been used in minutes yet it still opens new connections.

  • Its the same connection string
  • I ran SQL Sever Profiler I can see sp_reset_connection being called after every call.

Any help would be appreciated.

4

1 回答 1

2

如果连接来自不同的机器,则无法合并连接。连接要求两个端点都是连接。如果您正确使用连接池,应用程序会(从池中)实例化一个连接,使用该连接,然后在交换完成后立即删除它。

如果您正在编写单线程桌面应用程序,另一种常见且简单的策略是打开一个连接,只要应用程序正在运行,就让该连接保持打开状态。

您可以控制创建的连接数等。有关连接池的更多详细信息,请参阅MS 文章。

IIRC,除非连接字符串相同,否则不共享连接池。

于 2013-09-06T15:55:58.907 回答