Page 1 of 1

return connection pool with/whthout using block

Posted: Tue 20 Jan 2015 05:55
by waertf
If the connection pool is enable,what the situation if the connection object out of using block? return to pool or auto dispose(if dispose, is meaning disconnect server actually?)
1. with using block

Code: Select all

void connect()
{
using (var pgSqlConnection = new PgSqlConnection(pgCSB.ConnectionString))
{
pgSqlConnection.Open();
pgSqlConnection.Close();
}
}
2.without using block

Code: Select all

void connect()
{
var pgSqlConnection = new PgSqlConnection(pgCSB.ConnectionString);
pgSqlConnection.Open();
pgSqlConnection.Close();
}

Re: return connection pool with/whthout using block

Posted: Wed 21 Jan 2015 15:36
by Pinturiccio
The Dispose() method calls the Close() method internally; therefore, you don't need to call Close() if you use a using block.

When calling Close() or Dispose(), the PgSqlConnection object and its internal resources are freed for garbage collection, but the internal object with the physical connection to the server is placed to the pool when 'Pooling=true'.