Currently;”.
Very nice, I’ve been waiting for it for a long time! Good job!
This is awesome. Is TransactionScope also the way to handle single database (multi-table) transactions?
I tried out the code, the connection was against single SQL Server database but different tables, in code flow below, after Child Class 2 has set the TransactionConsistent option to false and calls a method in Child Class 3, if I put the code within a Transaction Scope, I get "Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." if I don’t put it in a Transaction Scope, I get "The transaction has already been implicitly or explicitly committed or aborted" If I set the TransactionConsitent bit to true, everything works fine..So how to handle these set of cases? I can send in the actual code in case you need them..
//Code flow
//Class 1
Using (TransactionScope1)
{
//Open Connection 1
//Create Child Class 1
}
//Child Class 1
Using (TransactionScope2)
{
//Open Connection 2
//User Code
//Set Transaction Consistent to false
//Create Child Class 2
}
//Child Class 2
{
//No Transaction Scope, just a read operation
//Open Connection <- Exception Thrown as "The transaction has already been implicitly or explicitly committed or aborted"
}
What about [Autocommit] and [TransactionOption] attributes similar to that of the support we have in EnterpriseServices. I remember seeing similar attributes in a presentation from the PDC on Distributed Transactions using the Light weight Transaction Manager.
We are currently using Remoting interception (derived from ContextBound and applied ContextAttributes) for Distributed Transactions without using EnterpriseServices. Since these classes are not documented and might become internal in future releases of the framework we want to move away from this model and use the System.Transaction classes instead, so we were comparing the options available and wanted to know if similar attributes would be made available in the future…basically we are looking for applying the "using TransctionScope" block through attributes and avoid having to write the plumbing code…
Thanks !
Simple transaction need that I can’t figure out how to do it in 1.x *or* with new model:
I want transparent transactedness for all my ASP.NET pages. By which I mean, each page request should take place in its own transaction; if page load runs to completion with no exception (or terminates with the implicit ThreadAbortException thrown by Response.End, which is usually success in practice) the transaction is committed; otherwise (any other exception) it’s rolled back. I’d also like to be able to access the transaction for rollback by hand, if there’s an error condition that I want to handle some other way than by letting the exception propagate out.
I thought I could do that with a <%@ Page Transaction=something %> directive, but none of the available values of the Transaction attribute are, well, comprehensible to me at all. I tried a couple of the most likely-sounding candidates and ended up with the site completely screwed, giving an error even after I removed the transaction directive. I didn’t try again after that; there are other developers working on the site too.
Even with the new transaction stuff described in your blog, I still can’t figure out how I would implement this behavior. I can’t use ‘using’ because there’s nowhere to place the ‘using’ block such that its scope covers all of the page lifecycle. I’m sure I’m missing something obvious – like some documentation that makes sense? 😉
TO: Kyle Tinsley
Yes, TransactionScope is also good for single-database transactions. In fact, when only one resource manager is used and this resource manager supports promotable transactions, there will be no overhead.
To: Krishna
I have to see the code to give you an answer. You can send it to me by using the
One thing that you need to be careful is that it is not recommended to execute any code after you set the consistent flag inside a transaction scope. And in general, if you do set it to false, that means you are in a bad state and you want to abort everything as soon as possible, i.e. don’t do any further work as part of that transaction because you know it will abort.
To: Krishna 2nd comment
Currently there are no attributes for transactions as part of System.Transactions namespace. They are provided either by EnterpriseServices or will be by "Indigo" (these are the attributes you’ve seen at PDC). Or you can write your own attributes. Please, make sure to read my disclaimer.
To: Stuart
Did you look at ContextUtil.SetAbort()? I believe this is what you are looking for.
See more info at
Thanks Florin, I have submitted the code in the link provided..the subject is "System.Transactions Sample Code that throws Exception..See note on Blog" let me know if you need more information..
how to check the consistency of the transaction?..say a child class has set the transaction scope consistent flag to false..is it possible to check this in the parent class after the call to the child??..
on the note on Attributes..is there special attribute that we need to inherit from to make the transaction scopes transparent on a method or a class??
Thanks
Ping Back来自：blog.csdn.net
TrackBack From:
Hey All,
Using Beta 2 of VS2005 and I’m attempting to use transaction scope in the business layer with no success. Seems to work ok on XP but when we run in a Windows 2003 environment, it fails with access denied.
Any ideas?
Mike
To Mike: It’s unusual to get an access denied. I don’t know of any case when System.Transactions or DTC return "Access Denied". You should post more details about your scenario.
When two connections opened in the same transactionscope, it triggers a DTC transaction, not a local transaction, even if two connections point to the same database. I use win2003 and sql2005 with .net 2.0 beta 2.
Is this behaviour as designed?
Thanks
I have the same trouble than Mike (see post on Thursday, September 15, 2005 11:24 AM) with the System.Transacions.
We are migrating code from Windows XP and VS2005 beta 2 to Windows Server 2003 and the VS2005 november release. We have the SQL Server in a different server and we are getting the exception message "The transaction has already been implicitly or explicitly committed or aborted".
The code is like this:
using (TransactionScope ts = new TransactionScope())
{
TableAdapter1 ta1 = new TableAdapter1();
TableAdapter2 ta2 = new TableAdapter2();
try
{
ta1.Update(dataset);
ta2.Update(dataset);
ts.Complete();
dataset.AcceptChanges();
return true;
}
catch
{
dataset.RejectChanges();
}
finally
{
ts.Dispose();
}
}
Thanks
for the TransactionScope – already committed/aborted one can read this very
useful article:
bye, good luck
To: hbzhang
The behavior is currently by design. The WebData/ADO team may be able to optimize this in the future if we (me and you) ask them nicely 🙂
To: Jesús
Shouldn’t you put ts.Complete() after dataset.AcceptChanges? I’m not sure what AcceptChanges does, but if is trying to use the current transaction, that might explain why you are getting the exception.
To : Jesus,
Why are u doing ts.Dispose? You are already using “using”.
What version of Visual Studio 2005 is needed for the transactional support, or am I just really lost here?
I put in using System.Transactions; (Well tried to, doesn’t show up in intellisense) but am unable to access anything in the namespace.
Was this dropped from the final release of VS2K5 or do I need something better than Standard Edition?
I am using TransactionScope object to achieve transaction support across 2 components that could have database interactions. Both components make connections to the database and change data. Even though both components connect to the same database with the same connection string, when the second connection is made the transaction escalates to a Distributed Transaction. Is it possible to change this behavior so that the transaction doesn’t escalate since the connections are to the same database with the same connection string. The main reason I want to prevent transaction escalation is our product has to work in WindowsXPSP2 and DTC service is disabled by default.
I am geting Transaction aborted Execption, i am using sql Server 2000.
using (TransactionScope scope = new TransactionScope()
{
Store_to_database(int vl,int v2)
scope.Complete();
}
In the Store_to_database function
i am opening a connection to database, inserting the record. but i m geting Execption
“The Transaction has Aborted” on connection.open() statement.
please Help me…...