You asked if the following are similar:
SqlConnection cn;
SqlTransaction st;
st=cn.BeginTransaction;
V/s
SqlConnection cn;
SqlTransaction st=new SqlTransaction();
However, the question does not quite make sense since the latter one does not compile. In other words, you cannot instantiate a
SqlTransaction
class directly. This is because the constructor is defined as
internal
.
If you try to compile the latter code you'll get an error
Severity Code Description
-------- ------ ----------------------------------------------------------------------
Error CS1729 'SqlTransaction' does not contain a constructor that takes 0 arguments
Probably the reason for preventing direct instantiation of
SqlTransaction
class is that during
BeginTransaction
call, several checks are carried out and assignments made, for example:
- default isolation level is set to read committed if not specified
- connection is validated
- the connection is restored if needed and broken
- and so on...