Discussion:
Commit nested transaction
(too old to reply)
Jose Luis
2009-03-25 15:06:43 UTC
Permalink
Hi,

In the code below:

<<snip begin>>
begin transaction1
begin transaction2

commit transaction2
rollback transaction1
<<snip begin>>


Is it posible to commit the inner transaction even though the outer
one is rolled back?

Thanks in advance,
Jose Luis.
mpeppler@peppler.org [Team Sybase]
2009-03-25 16:13:32 UTC
Permalink
Post by Jose Luis
Hi,
<<snip begin>>
begin transaction1
          begin transaction2
          commit transaction2
rollback transaction1
<<snip begin>>
Is it posible to commit the inner transaction even though the outer
one is rolled back?
Thanks in advance,
Jose Luis.
No, I don't think that it's possible to commit the inner transaction
and rollback the outer one.

It *is* possible to rollback an inner transaction if you use
savepoints (see the "save transaction" command in the reference
manual).

Note that nested transactions do NOT require transaction names, and in
general it is better not to use them. Just keep in mind that a commit
closes the current transaction, and a rollback does a complete
rollback to the outer-most transaction.

Michael
Bret Halford [Sybase]
2009-03-25 20:49:40 UTC
Permalink
Post by ***@peppler.org [Team Sybase]
Post by Jose Luis
Hi,
<<snip begin>>
begin transaction1
begin transaction2
commit transaction2
rollback transaction1
<<snip begin>>
Is it posible to commit the inner transaction even though the outer
one is rolled back?
Thanks in advance,
Jose Luis.
No, I don't think that it's possible to commit the inner transaction
and rollback the outer one.
It *is* possible to rollback an inner transaction if you use
savepoints (see the "save transaction" command in the reference
manual).
Note that nested transactions do NOT require transaction names, and in
general it is better not to use them. Just keep in mind that a commit
closes the current transaction, and a rollback does a complete
rollback to the outer-most transaction.
Michael
I'll take the contrarian view. There is one way to do this,
which is to write the inner transaction in the form of a stored
procedure, and then have the outer transaction execute that
procedure as a remote procedure call to a loopback entry
in the interfaces file, using a "traditional" rpc call
(nontransactional) rather than CIS rpc handling (transactional).



declare @servernetname varchar(30)
select @servernetname=srvnetname
from master..sysservers
where srvname=@@servername

exec sp_addserver loopback, NULL, @servernetname


Then in your main transaction:

set cis rpc handling off
execute loopback.database..procname
set cis rpc handling on

The general concept is known as an "autonomous transaction";
there is an open feature request 270817 for a more straightforward
approach for them in ASE.
mpeppler@peppler.org [Team Sybase]
2009-03-26 10:25:42 UTC
Permalink
Post by ***@peppler.org [Team Sybase]
Post by Jose Luis
Hi,
<<snip begin>>
begin transaction1
          begin transaction2
          commit transaction2
rollback transaction1
<<snip begin>>
Is it posible to commit the inner transaction even though the outer
one is rolled back?
Thanks in advance,
Jose Luis.
No, I don't think that it's possible to commit the inner transaction
and rollback the outer one.
It *is* possible to rollback an inner transaction if you use
savepoints (see the "save transaction" command in the reference
manual).
Note that nested transactions do NOT require transaction names, and in
general it is better not to use them. Just keep in mind that a commit
closes the current transaction, and a rollback does a complete
rollback to the outer-most transaction.
Michael
I'll take the contrarian view.  There is one way to do this,
which is to write the inner transaction in the form of a stored
procedure, and then have the outer transaction execute that
procedure as a remote procedure call to a loopback entry
in the interfaces file, using a "traditional" rpc call
(nontransactional) rather than CIS rpc handling (transactional).
from master..sysservers
set cis rpc handling off
execute loopback.database..procname
set cis rpc handling on
The general concept is known as an "autonomous transaction";
there is an open feature request 270817 for a more straightforward
approach for them in ASE.
Thanks Bret - I kinda forgot about that (somewhat convoluted)
technique... :-)

Michael
ThanksButNo
2009-03-26 06:07:59 UTC
Permalink
Post by Jose Luis
Hi,
<<snip begin>>
begin transaction1
begin transaction2
commit transaction2
rollback transaction1
<<snip begin>>
Is it posible to commit the inner transaction even though the outer
one is rolled back?
Thanks in advance,
Jose Luis.
What's the point of making it an INNER transaction if you want
that kind of functionality?

Just do it this way:

begin transaction1
...
commit transaction1
begin transaction2
...
commit transaction2

The whole POINT of having nested transactions IS to be able to
roll back the whole shooting match, no matter what other subsets
might have succeeded, should the application detect some problem
some where.

/:-/
Jose Luis
2009-03-26 07:31:39 UTC
Permalink
Post by ThanksButNo
Post by Jose Luis
Hi,
<<snip begin>>
begin transaction1
          begin transaction2
          commit transaction2
rollback transaction1
<<snip begin>>
Is it posible to commit the inner transaction even though the outer
one is rolled back?
Thanks in advance,
Jose Luis.
What's the point of making it an INNER transaction if you want
that kind of functionality?
begin transaction1
...
commit transaction1
begin transaction2
...
commit transaction2
The whole POINT of having nested transactions IS to be able to
roll back the whole shooting match, no matter what other subsets
might have succeeded, should the application detect some problem
some where.
/:-/
The outer transaction is launched by a external process. I have only
access to the sql code executed by the outer transaction. My target is
to keep some trace even though the outer transaction is rolled back.

Regards,
Jose Luis
ThanksButNo
2009-03-26 20:13:18 UTC
Permalink
....
Post by Jose Luis
Post by ThanksButNo
The whole POINT of having nested transactions IS to be able to
roll back the whole shooting match, no matter what other subsets
might have succeeded, should the application detect some problem
some where.
The outer transaction is launched by a external process. I have only
access to the sql code executed by the outer transaction. My target is
to keep some trace even though the outer transaction is rolled back.
Well, three ideas come to mind:

You can try Bret's stored procedure idea --

Or you can fire off a separate transaction BEFORE you run
the external process, and another one AFTERWARDS which can
compare notes --

Or you can contact the people who made the external process
and negotiate some sort of communication interface -- ?

/:-/
J
2009-03-26 22:38:55 UTC
Permalink
On Thu, 26 Mar 2009 00:31:39 -0700 (PDT), Jose Luis
<***@gmail.com> wrote:

Why not just use an extended procecure for the logging? It would not
be a part of any transactional interface. The same could be said for
an openserver rpc.

Jay
Post by Jose Luis
Post by ThanksButNo
Post by Jose Luis
Hi,
<<snip begin>>
begin transaction1
=A0 =A0 =A0 =A0 =A0 begin transaction2
=A0 =A0 =A0 =A0 =A0 commit transaction2
rollback transaction1
<<snip begin>>
Is it posible to commit the inner transaction even though the outer
one is rolled back?
Thanks in advance,
Jose Luis.
What's the point of making it an INNER transaction if you want
that kind of functionality?
begin transaction1
...
commit transaction1
begin transaction2
...
commit transaction2
The whole POINT of having nested transactions IS to be able to
roll back the whole shooting match, no matter what other subsets
might have succeeded, should the application detect some problem
some where.
/:-/
The outer transaction is launched by a external process. I have only
access to the sql code executed by the outer transaction. My target is
to keep some trace even though the outer transaction is rolled back.
Regards,
Jose Luis
Loading...