Sqltransaction
I am trying to insert in to tables in the multiple db and I want to one of them is not execute ,all stetement is rooleback. i want use sql transaction but i dont know how to use sql transaction and transactionscope in c# i transaction scope
try
{
using (tScope = new TransactionScope(TransactionScopeOption.Required,TOption))
{
ConAcnt.open();
SqlCommand Com1 = new SqlCommand("INSERT",ConAcnt);
Com1.ExecuteNonQuery();
ConBase.open();
Com2 = new SqlCommand("INSERT",ConBase);
Com2.ExecuteNonQuery();
tScope.Complete();
}
catch (Exception ex)
{
tScope.Dispose();
}
}
i want when the com2 not execute,com1 is rooleback,but commit the transaction,com2 is execute and com1 not save in db