OLE DB has a sneaky feature where if your current connection is busy, it will silently open more database connections.
- these happen without your knowledge
- and they are not taken from, or returned to, the connection pool
With the SQL Server 2005 "native client", Microsoft introduced a feature where one connection could support Multiple Active Record Sets; so that you can officially have multiple recordsets active over a single connection. But they note it's a tricky thing to enabled, which is why it's been opt-in since beta 2 of the feature.
Secret connections? Really?
Microsoft notes this behavior:
Using ADO with SQL Server Native Client
In prior versions of the OLE DB provider, this code would cause an implicit connection to be created on the second execution because only one active set of results could be opened per a single connection. Because the implicit connection was not pooled in the OLE DB connection pool this would cause additional overhead. With the MARS feature exposed by the SQL Server Native Client OLE DB provider, you get multiple active results on the one connection.
It's also noted by John C. Gordon [MSFT] in the Microsoft forums: (archive)
In OLE DB, there is something called an "implicit connection" spawned when a query is performed while an active resultset is still pending. These are not apparent to the user, as the original poster noticed. I know that SQLNCLI, SQLNCLI10 implement these, but it I do not remember if SQLOLEDB does. What then happens is the server has 2 connections and each one has one pending resultset. This is unpleasant when the licensing model you choose is by connection.
It's also noted in a MARS announcement blog entry: (archive)
Using MARS with SQL Native Client [Chris Lee]
The second result set is using a new connection each time it is opened. This clearly has some overhead (and it turns out that the additional connections aren’t pooled, so the overhead is for a full server connection network protocol exchange each time). This is the default behavior for SQLOLEDB and SQL Native Client (OLE DB) – a new implicit connection is spawned when the main connection is busy with a default result set.
It's a feature deep inside OLE DB, designed to make data access easier.
Bonus Chatter
- OLE DB is a low level, complicated, API
- ADO is simplified wrapper around OLE DB
How to turn it off?
This automatic creation of secondary connections is obviously not good. It's so not good that the SQL Server ODBC driver does not do it (because it's a feature deep inside OLE DB, and comes to SQL Server's OLE DB drivers for free. It's not a feature inside ODBC).
I want to make sure i'm not doing it. To this end i want the driver to throw an error at the point in my code where i accidentally try to do this.
How can i turn off OLE DB implicit additional connections?