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?
在ASP.NET页面加载期间,我打开和关闭页面中包含的多个控件内的多个System.Data.SqlClient.SqlConnections。我认为最好创建一个连接的“池”,并在打开连接时检查连接字符串是否与池中的打开连接的连接字符串匹配,然后返回该连接。我期待看到页面加载时间的差异,但我没有看到任何变化。我知道使用PHP,如果您尝试使用已在该页面请求中使用的连接字符串打开新连接,它将不会尝试打开新连接,而是返回现有的打开连接。这是真的与.NET?
2 个解决方案
#1
3
Connection pooling is an essential feature of ADO.NET.
连接池是ADO.NET的基本功能。
Read this MSDN article or some of the other resources available on the net, like this blog post
阅读此MSDN文章或网上提供的一些其他资源,例如此博客文章
#2
0
Yes, that is basically how connection pooling works in ADO.NET.
是的,这基本上是连接池在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.
在Connection-instance上调用Open()时,它不一定会打开连接。它从池中获取打开的连接,与连接字符串匹配。 Close()将连接释放回池中。
#1
3
Connection pooling is an essential feature of ADO.NET.
连接池是ADO.NET的基本功能。
Read this MSDN article or some of the other resources available on the net, like this blog post
阅读此MSDN文章或网上提供的一些其他资源,例如此博客文章
#2
0
Yes, that is basically how connection pooling works in ADO.NET.
是的,这基本上是连接池在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.
在Connection-instance上调用Open()时,它不一定会打开连接。它从池中获取打开的连接,与连接字符串匹配。 Close()将连接释放回池中。