return connection pool with/whthout using block

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
waertf
Posts: 9
Joined: Sat 07 Jun 2014 01:52

return connection pool with/whthout using block

Post by waertf » Tue 20 Jan 2015 05:55

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();
}

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: return connection pool with/whthout using block

Post by Pinturiccio » Wed 21 Jan 2015 15:36

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'.

Post Reply