return connection pool with/whthout using block

return connection pool with/whthout using block

Postby 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();
}
waertf
 
Posts: 9
Joined: Sat 07 Jun 2014 01:52

Re: return connection pool with/whthout using block

Postby 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'.
Pinturiccio
Devart Team
 
Posts: 1982
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL