COM+ question: SetAbort not rolling back transaction? 
Author Message
 COM+ question: SetAbort not rolling back transaction?

I'm trying to get the hang of transactions with COM+ and VB, and I'm having
some trouble with rolling things back when they fail.

I've got a VB component that calls two subcomponents, each of which tries to
insert a record into the same table, using the same primary key value.  The
first insert statement works fine, and naturally the second one fails.
However, when I try to rollback this transaction in the main component, the
first insert remains in the table-- not what I wanted.

Here's the main component's function, the one which creates and runs the two
subcomponents:

'-------------------------------------------------------------
Public Function superComponentDoSomething() as Boolean

    Dim objContext as COMSVCSLib.ObjectContext
    Dim testComponent, liveComponent as subComponent
    Dim bResult, bResult2 as Boolean

    Set objContext = GetObjectContext()

    <....>

    bResult = testComponent.insertTitle("hello",31) 'This works fine
    bResult2 = liveComponent.insertTitle("goodbye",31) ' This call doesn't

    if (bResult =false or bResult2 = false) then
        objContext.SetAbort
        superComponentDoSomething = false
    else
        objContext.SetComplete
        superComponentDoSomething = true
    end if

End Function
'-----------------------------------------------

As I mentioned, the subcomponents try to insert records into a SQL table,
like so:

'-----------------------------------------------------------------------
Public Function insertTitle(ByVal title as String, ByVal myID as Integer)
On error goto err_handle

    Dim objContext as COMSVCSLib.ObjectContext
    Set objContext = GetObjectContext()

    <...>
    strSQL = "Insert into myTable (uniqueValue,myTitle) values (" & myID &
",'" & title &"')"
    Connection.Execute(strSQL )
    objContext.SetComplete
    insertTitle=true
    Exit Function

err_handle:
    objContext.SetAbort
    insertTitle = false

End Function
'-----------------------------------------------

The first time I call this "insertTitle" function, it works fine, does the
insert.  Of course, when I do it again, trying to use the same primary key,
it blows up, and the SetAbort method is called, both in the subComponent,
*and* in the main component's method.

What I thought would happen is that both insert statements would have been
aborted by the main component's SetAbort call, but that's not happening for
whatever reason.

  If it helps, the main component's transaction mode is set to "Requires New
Transaction", while the subComponents are set to "Requires Transaction".  If
you can see what I'm doing wrong above, or what assumptions I'm making, I'd
be grateful the hear about it.  Thanks!



Sat, 26 Jul 2003 09:00:47 GMT  
 COM+ question: SetAbort not rolling back transaction?
Yeah, it looks like user error on this one-- for some reason I had my
component running in the "client" process space under component services,
and not under the server's direction, which I assume is necessary for DTC to
do it's thing.  Thanks for the tips, though!


Quote:
> I'm trying to get the hang of transactions with COM+ and VB, and I'm
having
> some trouble with rolling things back when they fail.

> I've got a VB component that calls two subcomponents, each of which tries
to
> insert a record into the same table, using the same primary key value.
The
> first insert statement works fine, and naturally the second one fails.
> However, when I try to rollback this transaction in the main component,
the
> first insert remains in the table-- not what I wanted.

> Here's the main component's function, the one which creates and runs the
two
> subcomponents:

> '-------------------------------------------------------------
> Public Function superComponentDoSomething() as Boolean

>     Dim objContext as COMSVCSLib.ObjectContext
>     Dim testComponent, liveComponent as subComponent
>     Dim bResult, bResult2 as Boolean

>     Set objContext = GetObjectContext()

>     <....>

>     bResult = testComponent.insertTitle("hello",31) 'This works fine
>     bResult2 = liveComponent.insertTitle("goodbye",31) ' This call doesn't

>     if (bResult =false or bResult2 = false) then
>         objContext.SetAbort
>         superComponentDoSomething = false
>     else
>         objContext.SetComplete
>         superComponentDoSomething = true
>     end if

> End Function
> '-----------------------------------------------

> As I mentioned, the subcomponents try to insert records into a SQL table,
> like so:

> '-----------------------------------------------------------------------
> Public Function insertTitle(ByVal title as String, ByVal myID as Integer)
> On error goto err_handle

>     Dim objContext as COMSVCSLib.ObjectContext
>     Set objContext = GetObjectContext()

>     <...>
>     strSQL = "Insert into myTable (uniqueValue,myTitle) values (" & myID &
> ",'" & title &"')"
>     Connection.Execute(strSQL )
>     objContext.SetComplete
>     insertTitle=true
>     Exit Function

> err_handle:
>     objContext.SetAbort
>     insertTitle = false

> End Function
> '-----------------------------------------------

> The first time I call this "insertTitle" function, it works fine, does the
> insert.  Of course, when I do it again, trying to use the same primary
key,
> it blows up, and the SetAbort method is called, both in the subComponent,
> *and* in the main component's method.

> What I thought would happen is that both insert statements would have been
> aborted by the main component's SetAbort call, but that's not happening
for
> whatever reason.

>   If it helps, the main component's transaction mode is set to "Requires
New
> Transaction", while the subComponents are set to "Requires Transaction".
If
> you can see what I'm doing wrong above, or what assumptions I'm making,
I'd
> be grateful the hear about it.  Thanks!



Mon, 28 Jul 2003 00:05:31 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. SetAbort does not roll back transaction

2. Roll back transaction Error handling

3. RDO Problem when rolling back transaction - Function sequence error

4. Rolling back transactions

5. MTS, VB and rolling back transactions

6. Why to use COM+ transaction and not just SQL Server transaction

7. Why to use COM+ transaction and not just SQL Server transaction

8. To Transaction or Not to Transaction that is the question

9. MTS / DTC not rollling back transaction

10. MTS / DTC not rollling back transaction

11. MTS / DTC not rollling back transaction

12. COM+ error handling on SetAbort

 

 
Powered by phpBB® Forum Software