Home All Groups Group Topic Archive Search About

Queued Components and TransactionScope

Author
25 Jul 2006 9:17 PM
John
Hi,

I have an app that uses Queued Components.  The queue is set as
transactional and the transaction is set to Supported (I've also tried
Required).  Everything is running on the same box (tried XP and 2k3).  In my
app I wrap the queued component call in a TransactionScope.  I'm using
EnterpriseServicesInteropOption.Full in creating the scope.  Right after
queuing the component I intentionally throw an exception and don't complete
the scope.  The message stays on the queue and gets processed.  This is a
simplified version of what my program really does, which is call a database
update within that same scope.  When something fails I want the entire
transaction rolled back; DB and MSMQ.  What actually happens though is that
the DB rolls back but MSMQ doesn't.  I created the simplified version just
to see if I could get MSMQ to roll back, but I can't.  So what am I missing?

John

Author
26 Jul 2006 6:52 AM
Kevin Yu [MSFT]
Hi John,

Could you send the simplified version to me so that I can troubleshoot on
it? Remove 'online' from the nospam alias is my real email.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
26 Jul 2006 11:36 PM
John
Hi Kevin,

Thank you for the reply.  The simplified version still uses a huge library
that does the queueing among other things.  I can't send you that.  I'll see
if I can work up a really simple stand-alone version that doesn't have any
of that.  But in the mean time, is there anything special I need to do other
than what I've already described?  This should work, right?

John


Show quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:5mD1kAIsGHA.4424@TK2MSFTNGXA01.phx.gbl...
> Hi John,
>
> Could you send the simplified version to me so that I can troubleshoot on
> it? Remove 'online' from the nospam alias is my real email.
>
> Kevin Yu
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
>
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Author
27 Jul 2006 8:37 AM
Kevin Yu [MSFT]
Hi John,

If the transaction is rolled back, please make sure that the
TransactionScope is disposed successfully. Putting the TransactionScope
object in a using block is a good idea.

http://msdn2.microsoft.com/en-us/library/system.transactions.transactionscop
e.aspx

Currently, I have no other ideas on this issue. If you have a repro sample,
please feel free to send it to me, I'll take a look. Thank you for your
understanding.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
14 Aug 2006 5:52 PM
John
Hi Kevin,

I finally got back on this project and created a test that demonstrates my
problem.  The entire solution is attached.  Here's the relevant code from
the test program:

using (TransactionScope scope = new TransactionScope(
  TransactionScopeOption.Required,
  new TransactionOptions(),
  EnterpriseServicesInteropOption.Automatic))
{
  IQueuedComponent queuedComponent =
(IQueuedComponent)Marshal.BindToMoniker(moniker);
  queuedComponent.Send(server, recipient, "Hello World");
  if (SomeCondition)
    throw new ApplicationException("Forced Failure.");
  scope.Complete();
}

SomeCondition is actually code that determines whether or not I want to
throw an exception for testing purposes (see actual code).  When it throws
the exception, scope.Complete() is not called and the TransactionScope
should be disposed without committing the transaction, or at least that's my
understanding.  However, the component is queued and runs successfully
anyway.  I have also tried explicitly disposing the scope just before
throwing the exception but that had no effect.  The funny thing is that the
component isn't actually queued until the program ends; I don't understand
that.

In my real program it is a SqlException that is thrown from inside the
TransactionScope block.  That's what I'm actually trying to do--wrap a
transaction around the queue and a database update (SQL Server 2000).  If
either fails I want them both rolled back.

Am I doing something wrong?  Thanks for looking at this.

John



Show quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:TIeIxfVsGHA.4424@TK2MSFTNGXA01.phx.gbl...
> Hi John,
>
> If the transaction is rolled back, please make sure that the
> TransactionScope is disposed successfully. Putting the TransactionScope
> object in a using block is a good idea.
>
> http://msdn2.microsoft.com/en-us/library/system.transactions.transactionscop
> e.aspx
>
> Currently, I have no other ideas on this issue. If you have a repro
> sample,
> please feel free to send it to me, I'll take a look. Thank you for your
> understanding.
>
> Kevin Yu
> Microsoft Online Community Support
> ==================================================
>
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>

[attached file: QCTransaction.zip]
Author
16 Aug 2006 9:29 AM
Kevin Yu [MSFT]
Hi John,

I did some research on this code and found that you're trying to use nested
transaction. Althrough you're using TransactionScopeOptions.Required, the
inner one is getting the outer transaction. So actually, there is only one
transaction here. When the inner one calls Complete, the Transaction is
committed.

So can you try to remove one TransactionScope? Or please try to use
TransactionScopeOption.RequiresNew in the inner transaction scope in the
Send method?

Please let me know if you have any problem.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
18 Aug 2006 3:57 PM
John
Kevin,

From everything I've read it was my understanding that if transaction scopes
are nested and the inner scope joins the outer scope, committing the outer
scope--not the inner one--commits the whole thing.  Is that not the case?

Either way, I removed the inner transaction scope, leaving only the one in
Main and I get the same behavior.

The other funny thing is that the message doesn't get queued until the
program ends--not at the point the scope.Complete() is called as I would
expect.  Can that be explained?

John

Show quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:mxeUIaRwGHA.5864@TK2MSFTNGXA01.phx.gbl...
> Hi John,
>
> I did some research on this code and found that you're trying to use
> nested
> transaction. Althrough you're using TransactionScopeOptions.Required, the
> inner one is getting the outer transaction. So actually, there is only one
> transaction here. When the inner one calls Complete, the Transaction is
> committed.
>
> So can you try to remove one TransactionScope? Or please try to use
> TransactionScopeOption.RequiresNew in the inner transaction scope in the
> Send method?
>
> Please let me know if you have any problem.
>
> Kevin Yu
> Microsoft Online Community Support
> ==================================================
>
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Author
22 Aug 2006 8:26 AM
Kevin Yu [MSFT]
Hi John,

Actually in this case, there is only one transaction here. Because
TransactionScopeOptions.Required will use the existing transaction. Would
you mind sending me an email so that we might discuss this issue? Remove
'online' from the nospam alias is my real email.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
30 Aug 2006 7:01 PM
John
Kevin,
Per your email request I am indicating here that this issue has not been
resolved yet.
John

Show quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:6SaWnScxGHA.2504@TK2MSFTNGXA01.phx.gbl...
> Hi John,
>
> Actually in this case, there is only one transaction here. Because
> TransactionScopeOptions.Required will use the existing transaction. Would
> you mind sending me an email so that we might discuss this issue? Remove
> 'online' from the nospam alias is my real email.
>
> Kevin Yu
> Microsoft Online Community Support
> ==================================================
>
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>

AddThis Social Bookmark Button