1

I have this repeating pattern in code:

using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  using (SqlTransaction trans = conn.BeginTransaction())
  {
  ...
  }
}

I know it doesn't hurt to use using for IDisposable, but for my reasons (might be off topic and too long to explain here), I prefer not to have the using for the SqlTransaction. I also looked at the demo from MSDN: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction(v=vs.110).aspx Which does not uses using or disposes the SqlTransaction.

Note that the SqlConnection have using which is fine.

Now my question, is disposing the SqlTransaction is required? will be SqlConnection dispose the SqlTransaction resources also? if yes, how can I verify that?

zig
  • 4,524
  • 1
  • 24
  • 68

0 Answers0