I need to include several stored procedure in a single transaction in a single database, if any of stored procedure fail then roll back transaction of all stored procedure procesed in the scope.
I work with SQL-SERVER 2008
I need to include several stored procedure in a single transaction in a single database, if any of stored procedure fail then roll back transaction of all stored procedure procesed in the scope.
I work with SQL-SERVER 2008
You can create a single stored procedure that starts a transaction and then calls the other stored procedures. If any of the inner stored procedures fail you can rollback the transaction. If you tell us what database platform you're using (MS SQL Server, MySQL, etc.) people may be able to provide more specific solutions.
Transactions are usually at the connection level, so if you want to control the transaction through a code api you should be able to use the same "transaction object".
.Net example http://msdn.microsoft.com/en-us/library/2k2hy99x.aspx using ado.net
begin transaction
begin try
exec proc_1
exec proc_2
exec proc_3
commit transaction
end try
begin catch
rollback transaction
end catch