Transaction Management in SqlServer and vb.net with TransactionScope

0
 Using tran As New Transactions.TransactionScope
            Try
                InsertaEnTabla1()
                InsertaEnTabla2()
                InsertaEnTabla3()
                tran.Complete()
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
    End Using

I am using this procedure to handle transactions in sqlserver, the point is that even if tran.com is not executed, it applies what was executed in the previous procedures, that is, if there is an exception in InsertInTable3 (), what you save in InsertTable1 () and InsertTable2 () is stored, does not Rollback ...

    
asked by avargasma 19.08.2016 в 19:12
source

1 answer

0

I think your problem comes from the side of the Try.

 Try 
   Using tran As New Transactions.TransactionScope
            InsertaEnTabla1()
            InsertaEnTabla2()
            InsertaEnTabla3()
            tran.Complete()
   End Using
 Catch ex As TransactionAbortedException
    writer.WriteLine("TransactionAbortedException Message: {0}", ex.Message)
 Catch ex As ApplicationException
    writer.WriteLine("ApplicationException Message: {0}", ex.Message)
 End Try

Anyway, you should use the codes that are inside "InsertInTable1" inside the Using.

    
answered by 19.08.2016 в 22:03