Transaction Scope and DTC Needs?

  • Thread starter Thread starter lucius
  • Start date Start date
L

lucius

I am trying to use a lightweight transaction to encapsulate multiple
sqlcommands on a connection (they update different databases in the
same named sqlserver instance) so if one update fails they will all
roll back. My development system is XP Pro and when I try to test the
below code I get an error about MSDTC being disabled.
using ( TransactionScope scope = new TransactionScope() )
{
using ( SqlConnection con = new SqlConnection(connstring) )
{
con.Open();
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
}
scope.Complete();
}

Can someone point out how to not use MSDTC when doing (lightweight)
transactions? The code will ultimately live in a class in an ASP.NET
2.0 web site.

Thanks.
 
Hello Lucius,
Thanks for Howdy's info.

According to your initial post, it seems you want to use Lightweight
transaction to enlist only one connection, however, meet an issue that
transaction scope told you it need enable MSDTC. Please correct me if I
misunderstand anything here. Thanks.

For Sql2k5, the transaction is managed by LTM until the second
SqlConnection connected to a different database comes into picture. But, In
Sql 2k, the transaction will be managed by MSDTC even if you have ONE
single database involved.

In my opinion, if your asp.net application connect single database and want
to use Lightweight transaction, I would like to recommend SqlTransaction.
SqlTransaction could only work on single databases and is Lightweight
transaction. The drawback is that you should explicitly enroll in the
transaction.

For the difference between SQLTranscation and TranscationScop, please refer
to
http://dotnetslackers.com/SQL/re-3498_SqlTransaction_vs_System_Transactions.
aspx
[SqlTransaction vs. System.Transactions ]

For an example about how to use SQLTranscation, please refer to
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqltransactio
n.commit.aspx
[SqlTransaction.Commit Method]

Hope this helps.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Lucius,

This is Wen Yuan again. Have you tried with SQLTranscation?
I just want to check if there is anything we can help with.
Please feel free to update here if you meet any futher issue.
We are glad to work with you.:)

Have a great day,
Sincerely,
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello
We are trying to use the Transaction Scope for our distributed transaction application. But we were unable to use it since the MS DTC is not configured properly(may be). We need some help or guidance to make this happen.

A brief description of what we are trying to do:

We have a database transaction and calls to a outside webservices which is enlisted in a Resource manager class. All this is clubed into one transaction scope so that all or nothing would be commited.
Any help is really appreciated.

Thank you.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Hello
We are trying to use the Transaction Scope for our distributed transaction application. But we were unable to use it since the MS DTC is not configured properly(may be). We need some help or guidance to make this happen.

A brief description of what we are trying to do:

We have a database transaction and calls to a outside webservices which is enlisted in a Resource manager class. All this is clubed into one transaction scope so that all or nothing would be commited.
Any help is really appreciated.

Thank you.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Back
Top