T
Tim Smith
I have a lot of code which follows the general pattern below.
Is there an easy (or hard) way of avoiding repeating the same code
over and over. I do need to manage the connection at this level, but
I am worried developers will forget to commit and/or close the
connection. If I could auto wrap around it somehow..?
public void SomeUpdate() {
OracleConnection connection = null;
OracleTransaction trans = null;
DataSet ds = null;
try
{
connection = GetConnection();
trans = connection.BeginTransaction();
//6-10 lines of code
trans.Commit();
connection.Close();
}
catch (Exception e)
{
trans.Rollback();
connection.Close(); LogError(this,e.Message +
Environment.NewLine + ids);
throw new Exception(e.Message + Environment.NewLine +
e.StackTrace.ToString());
}
}
Is there an easy (or hard) way of avoiding repeating the same code
over and over. I do need to manage the connection at this level, but
I am worried developers will forget to commit and/or close the
connection. If I could auto wrap around it somehow..?
public void SomeUpdate() {
OracleConnection connection = null;
OracleTransaction trans = null;
DataSet ds = null;
try
{
connection = GetConnection();
trans = connection.BeginTransaction();
//6-10 lines of code
trans.Commit();
connection.Close();
}
catch (Exception e)
{
trans.Rollback();
connection.Close(); LogError(this,e.Message +
Environment.NewLine + ids);
throw new Exception(e.Message + Environment.NewLine +
e.StackTrace.ToString());
}
}