Does .Net do clever connection management like PHP?

喜夏-厌秋 提交于 2019-12-06 14:53:14

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/177814/does-net-do-clever-connection-management-like-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!