简体   繁体   English

富客户端直接访问数据库的连接池

[英]Connection pooling for a rich client accessing a database directly

I have a legacy application WinForms that connect directly to a SQL Server 2005 database. 我有一个旧应用程序WinForms,它们直接连接到SQL Server 2005数据库。

There are many client applications open at the same time (several hundreds), so I want to minimize the number of connections to the database. 同时有许多客户端应用程序打开(数百个),因此我想最大程度地减少与数据库的连接数。

I can release connections early and often, and keep the timeout value low. 我可以及早并经常释放连接,并保持较低的超时值。

Are there other things I need to consider? 还有其他需要考虑的事情吗?

Try to use the same connection string when you create a new connection, so .Net will use one connection pool. 创建新连接时,请尝试使用相同的连接字符串,因此.Net将使用一个连接池。

Dispose your connection as soon as possible. 尽快处理您的连接。

You can set max pool size in the connection string itself to determine the max number of active connections. 您可以在连接字符串本身中设置最大池大小,以确定活动连接的最大数量。

You should consider introducing a connection pool. 您应该考虑引入连接池。 In the Java world you usually get this "for free" with an application server. 在Java世界中,通常可以通过应用程序服务器免费获得此功能。 However this would be oversized anyway if everything you care for is the database connection pooling. 但是,如果您所关心的只是数据库连接池,那么无论如何这都会过大。

The general idea is to have one process (on the server) open a limited number of parallel connections to the database. 总体思路是让一个进程(在服务器上)打开到数据库的有限数量的并行连接。 You would do this in some sort of "proxy" application (a mini application server of sorts) and re-use the expensive to create database connections for incoming connections to your app that are cheaper to create and throw away. 您将在某种“代理”应用程序(某种小型应用程序服务器)中执行此操作,然后重复使用昂贵的应用程序来为应用程序的传入连接创建数据库连接,而这些连接的创建和丢弃成本较低。

Of course this require some changes to the client side as well, so maybe it is not the ideal solution if you cannot accept that as a precondition. 当然,这也需要对客户端进行一些更改,因此,如果您不能接受将其作为前提条件,则可能不是理想的解决方案。

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

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