I would like to understand what does Clearpool
, Dispose
, Close
do in OracleConnection?
After exception occurs, I would like to get rid off the current connection and create a total new connection with the same connection string. How should I get rid off the old connection?
Should l clearpool firstly or dispose the connection? And what does clearpool vs dispose/close do?
My current code is like below:
public virtual void Dispose()
{
try
{
_connection.Close();
}
catch (Exception e)
{
}
finally
{
_connection.Dispose();
_connection.ClearPool();
_connection = null;
}
}
The easiest way to solve this is to create the connection inside a using
block. Everything inside that block will be disposed whenever the block execution finishes. Also, do NOT leave a catch with no action inside. This might end on a silent exception that you will be not aware of.
using(OracleConnection conn = new OracleConnection("yourConnStr"))
{
//ALL YOUR LOGIC INSIDE
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.