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

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

문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top