为什么我的 ADO.net 连接已关闭但 sp_who2 指示“正在等待命令” 连接?

发布于 2024-08-02 00:59:39 字数 281 浏览 3 评论 0原文

我们面临着严重的数据库性能问题。 在对程序进行了大量更改并尝试最小化锁之后,我们仍然存在一些性能问题。

当我在数据库中创建 sp_who2 时,有几个连接处于睡眠模式,“等待命令”。

也许如果我在关闭这些连接后自动关闭它们,我们可能会对服务器性能产生积极的影响。

我的问题是:如何使 ADO.NET 中的连接池在调用关闭时关闭我的连接,而不是将它们维持在睡眠模式?

PS:我知道处理性能是一个很大的话题,我们正在分析的不仅仅是这些。

We are facing serious problems with performance in the database. After making a lot of changes in the procedures, trying to minimize locks, we still have some problems of performance.

When I make a sp_who2 in the database, there are several connections in sleeping mode, "Awaiting command".

Maybe if I close these connections automatically after closing them, we could have a positive impact on the server performance.

And my question is: How to make connection pooling in ADO.NET close my connections when I call the close, instead of maintaining them in sleeping mode?

PS: I know handling performance is a large topic, we are analyzing more than just this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

轻许诺言 2024-08-09 00:59:39

连接池的要点是保持连接打开,以便当您需要新连接时它就在那里。 这样做的原因是打开连接是一件成本高昂的事情。 保持睡眠连接通常不会花费太多。

如果您想完全关闭连接,请关闭连接池。

The point of connection pooling is to keep connections open so that when you want a new connection it is there. The reason to do this is that opening a connection is a costly business. Keeping a sleeping connection does not usually cost much.

If you want to close the connection fully then turn connection pooling off.

所谓喜欢 2024-08-09 00:59:39

好吧,一个潜在的问题可能是连接池太多了!

连接池将基于精确连接字符串 - 如果两个连接字符串仅相差一个空格,则它们将被视为不同,并且将为每个连接字符串创建一个连接池。 因此,请确保所有连接字符串完全相同。

此外,将为每个 Windows 身份创建一个连接池 - 因此,如果您

server=myServer;Database=MyDatabase;integrated security=SSPI

为将连接的每个单独的 Windows 用户使用该连接池,则会创建一个连接池。

请参阅相关的 MSDN 文档(从顶部算起第四段) :

连接被分成池
通过连接字符串和 Windows
集成安全性时的身份
使用过。

因此,在负载较重的生产环境中,使用单个“应用程序用户”并只有一个连接池可能是一个更好的主意:

server=myServer;Database=MyDatabase;user id=MyAppUser;pwd=MyAppUserPwd

如果您确保所有客户端计算机都使用这个完全相同的连接字符串,则只有一个连接将创建池。

马克

Well, one potential problem you could have it too many connection pools!

Connection pool will be based on the exact connection string - if two connection strings differ only by a space, they'll be considered different, and one connection pool will be created for each. So make sure all your connection strings are absolutely identical.

Also, one connection pool will be created per Windows identity - so if you use

server=myServer;Database=MyDatabase;integrated security=SSPI

then for each separate Windows user that will connect, a connection pool is being created.

See the relevant MSDN documentation for this (fourth paragraph from the top):

Connections are separated into pools
by connection string, and by Windows
identity when integrated security is
used.

So in a heavy loaded production environment, it might be a better idea to use a single "application user" and have just a single connection pool:

server=myServer;Database=MyDatabase;user id=MyAppUser;pwd=MyAppUserPwd

If you make sure all client machines are all using this exact same connection string, only a single connection pool will be created.

Marc

似梦非梦 2024-08-09 00:59:39

您可以禁用连接池,但这不会提高性能。

连接池挂在连接上,这样应用程序就不必每次都创建新连接。 重用连接比打开新连接要快得多。

因此,休眠连接表明连接池正在工作,您不应该尝试摆脱它。

You could disable the connection pool, but that would not increase performance.

The connection pool hangs on the the connections, so that the application doesn't have to create a new connection each time. Reusing a connection is a lot faster than opening a new one.

So, the sleeping connections is an indication that the connection pool works, and you should not try to get rid of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文