c# - What is the better place to implement SQL Transaction? -


what better place implement sql transaction?

  1. within application program's business logic or
  2. in side stored procedure?

is bad practice open sql transaction within business logic code?

when handling complex business logic such batch process?

please explain me best way , why?

my opinion first of all: in stored procedure.

in sp simple using transactions, example (ms sql 2008r2)

 create procedure p_myprocedure   begin     begin transaction      begin try       select 'do someting here'       end try      begin catch         if @@trancount > 0         begin             rollback transaction;         end     end catch;      if @@trancount > 0         commit transaction;  end 

then can safely write business logic. , bother transaction on other levels, if wish.


Comments