.Net 是否像 PHP 一样进行巧妙的连接管理?

发布于 2024-07-07 00:57:57 字数 244 浏览 5 评论 0原文

在 ASP.NET 页面加载期间,我在页面中包含的多个控件内打开和关闭多个 System.Data.SqlClient.SqlConnections。 我认为创建一个连接“池”并在打开连接时检查连接字符串是否与池中打开的连接匹配,并返回该连接是一个好主意。 我原本期望看到页面加载时间有所不同,但我没有看到任何变化。 我知道,对于 PHP,如果您尝试使用该页面请求中已使用的连接字符串打开新连接,它不会尝试打开新连接,而是返回现有的打开连接。 .NET 也是如此吗?

During an ASP.NET page load I'm opening and closing multiple System.Data.SqlClient.SqlConnections inside multiple controls contained in the page. I thought it would be a good idea instead to create a "pool" of connections and when opening a connection check to see if the connection string matches that of an open connection in the pool, and return that connection. I was expecting to see a difference in the page load times, but I haven't seen any change. I know that with PHP if you attempt to open a new connection with a connection string that has already been used in that page request it won't attempt to open a new connection and will return the existing open connection instead. Is this true with .NET?

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

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

发布评论

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

评论(2

滥情稳全场 2024-07-14 00:57:57

连接池是 ADO.NET 的一项重要功能。

阅读这篇MSDN 文章或网上提供的一些其他资源,就像这个博客文章

Connection pooling is an essential feature of ADO.NET.

Read this MSDN article or some of the other resources available on the net, like this blog post

疑心病 2024-07-14 00:57:57

是的,这基本上就是 ADO.NET 中连接池的工作原理。

当您在 Connection 实例上调用 Open() 时,它不一定会打开连接。 它从池中获取与连接字符串匹配的打开连接。 Close() 将连接释放回池中。

Yes, that is basically how connection pooling works in ADO.NET.

When you call Open() on a Connection-instance, it doesn't necessarily open a connection. It fetches an open connection from the pool, matching the connection string. Close() releases the connection back into the pool.

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