Does DbConnection.Open always open a new database connection or can it reuse one of the connection pool?

StackOverflow https://stackoverflow.com/questions/10803356

Question

I'm unsure at which level the connection pool is implemented in .NET. When I call

using(var connection = new SqlConnection(connectionString))
{
    connection.Open();

Am I surely opening a new connection? Or could I possibly be reusing an active connection? The connection pool present in SqlConnection can be absent in other DbConnection implementations?

Était-ce utile?

La solution

Connection pooling happens automatically, unless you specify otherwise. If you scroll down to the section "Controlling Connection Pooling with Connection String Keywords" in the first link below, you'll see that the default for "pooling" is true.

http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

Connection pools get created without any intervention by you, as long as the connection string is exactly the same (uppercase/lowercase matters in this point.)

The same can be said for the OleDbConnection and Connection Pooling.
http://msdn.microsoft.com/en-us/library/ms254502.aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top