如何知道在 Windows 服务中打开了多少个 SQL 连接?

发布于 2024-07-06 07:49:55 字数 82 浏览 7 评论 0原文

我看到一些错误表明“连接泄漏”。 也就是说,连接未正确关闭并且池即将耗尽。 那么,我该如何对其进行检测,以准确了解在给定时间有多少个处于开放状态?

I'm seeing some errors that would indicate a "connection leak". That is, connections that were not closed properly and the pool is running out. So, how do I go about instrumenting this to see exactly how many are open at a given time?

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

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

发布评论

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

评论(7

末骤雨初歇 2024-07-13 07:49:55

如果您使用 .net,则 PerfMon 中有用于 SQL Server 的 .net 数据提供程序。 您可以在那里查看 NumberOfPooledConnections

性能监视器的屏幕截图

If you're using .net, there's the .net data provider for SQL server in PerfMon. You can look at NumberOfPooledConnections there

screenshot of perf monitor

焚却相思 2024-07-13 07:49:55

从数据库方面来看,主表中的 sp_who2 存储过程非常适合此操作。 它将向您显示与数据库的连接。 如果您正在寻找更多数据,也可以尝试分析。

sp_who2 stored procedure in the master table is nice for this from a database side. It will show you connections to the database. If you're looking for more data try profiling as well.

一城柳絮吹成雪 2024-07-13 07:49:55

实现一个服务,所有连接都通过该服务创建、打开和关闭。 在那里设立一个柜台。 每次打开或关闭连接时都使用日志记录框架进行记录。

Implement a service that all connections are created, opened and closed through. Hold a counter there. Log with your logging framework each time a connection is opened or closed.

得不到的就毁灭 2024-07-13 07:49:55

您可以使用探查器工具跟踪所有现有的以及打开和关闭的连接

您可以从企业管理器打开探查器

you can use the profiler tool to trace all existing and opening and closing connections

You can open profiler from enterprise manager

柳絮泡泡 2024-07-13 07:49:55

如果您使用的是 SQL 2000,则可以检查 SQL 2000 Enterprise Manager:

查看当前活动窗口
SQL Server 企业管理器,展开
一个服务器组,然后展开一个
服务器。 展开管理,然后
展开当前活动。 点击处理
信息。

当前服务器活动是
显示在详细信息窗格中。

http://technet.microsoft.com/en-us/library/cc738560 .aspx

(来自 Google 搜索:sql 2000 当前活动)

If you're using SQL 2000, you can check in SQL 2000 Enterprise Manager:

To view the Current Activity window In
SQL Server Enterprise Manager, expand
a server group, and then expand a
server. Expand Management, and then
expand Current Activity. Click Process
Info.

The current server activity is
displayed in the details pane.

(http://technet.microsoft.com/en-us/library/cc738560.aspx)

(From Google search: sql 2000 current activity)

惜醉颜 2024-07-13 07:49:55

您可以在 SQL Server Management Studio 或查询分析器中运行 sp_who2 来查看所有当前连接。 那就是 SQL Server。 我不确定您使用的是哪种 RDBMS。

另外,请检查您的代码并确保在不再需要连接时立即将其关闭。 对此保持肛门!

You could run sp_who2 in SQL Server Management Studio or Query Analyser to see all of your curent connections. That is SQL Server. I'm not sure which RDBMS that you are using.

Also, look in your code and make sure that you close a connection as soon as you don't need it anymore. Be anal about this!

苏辞 2024-07-13 07:49:55

使用“using”语句确保您的连接始终关闭,并且您将永远不会再遇到此问题:

using(SqlConnection connection = new SqlConnection())
{
...
} // connection is always disposed (i.e. closed) here, even if an exception is thrown

Use the "using" statement to ensure your connections are always closed and you'll never have this problem again:

using(SqlConnection connection = new SqlConnection())
{
...
} // connection is always disposed (i.e. closed) here, even if an exception is thrown
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文