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?
+3
A:
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
Ilya Kochetov
2008-10-07 10:01:05
A:
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.
JacquesB
2008-10-07 10:01:50