M
mehal.ua
Hi, I'm tyring to use .net transaction, I have code like this :
SqlConnection connection = Company.Instance.NewConnection();
using (connection) {
SqlTransaction transaction = connection.BeginTransaction();
try {
string stringSQL = GetSQLString();
SqlCommand command = new SqlCommand(stringSQL, connection,
transaction);
command.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception) {
transaction.Rollback();
throw;
}
}
How I understand when stringSQL is invalid transaction will rollback
automatically, am I right ? Than, when we going to catch, RollBack()
will thorow an error, am I right ?
SqlConnection connection = Company.Instance.NewConnection();
using (connection) {
SqlTransaction transaction = connection.BeginTransaction();
try {
string stringSQL = GetSQLString();
SqlCommand command = new SqlCommand(stringSQL, connection,
transaction);
command.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception) {
transaction.Rollback();
throw;
}
}
How I understand when stringSQL is invalid transaction will rollback
automatically, am I right ? Than, when we going to catch, RollBack()
will thorow an error, am I right ?