Using the distributed System.Transaction in several threads

I'm using Oracle DB 11.2.0.1 and ODP.NET 2.112.2.0.
I try to use the distributed transaction from System.Transaction namespace in several threads asynchronously. Here is the test console application. It creates new TransactionScope, creates 2 connections and opens them. At this time the transaction becomes distributed, because there are 2 opened connection in it. Then 2 INSERT commands are executed simultaneously in the same transaction (via Parallel.ForEach):
     class Program
          private static string ConnectionString = "MyConnectionString";
          private static void Main(string[] args)
               cleanup();
               for (int i = 0; i < 100; i++)
                    try
                         init();
                         run();
                         check();
                         Console.WriteLine("ITERATION {0} IS OK", i);
                    catch (Exception ex)
                         Console.WriteLine("ERROR AT ITERATION {0}: {1}", i, ex);
                         //break;
                    finally
                         cleanup();
          // main method
          private static void run()
               using (var scope = new TransactionScope())
                    using (var connection1 = new OracleConnection(ConnectionString))
                    using (var connection2 = new OracleConnection(ConnectionString))
                         connection1.Open();
                         connection2.Open();
                         Transaction tx = Transaction.Current;
                         if (tx.TransactionInformation.DistributedIdentifier == Guid.Empty)
                              throw new InvalidOperationException("tx.TransactionInformation.DistributedIdentifier == Guid.Empty");
                         var queries = new ConcurrentDictionary<OracleConnection, string>();
                         queries[connection1] = "INSERT INTO T1 VALUES ('AAA')";
                         queries[connection2] = "INSERT INTO T2 VALUES ('BBB')";
                         Parallel.ForEach(
                              queries,
                              pair =>
                                   using (var innerScope = new TransactionScope(tx))
                                        OracleCommand cmd = pair.Key.CreateCommand();
                                        cmd.CommandText = pair.Value;
                                        cmd.ExecuteNonQuery();
                                        innerScope.Complete();
                    scope.Complete();
          // check results
          private static void check()
               using (var connection = new OracleConnection(ConnectionString))
                    connection.Open();
                    OracleCommand cmd = connection.CreateCommand();
                    cmd.CommandText = "SELECT COUNT(1) FROM T1";
                    int n1 = Convert.ToInt32(cmd.ExecuteScalar());
                    if (n1 != 1)
                         throw new Exception("COUNT(T1) != 1");
                    cmd.CommandText = "SELECT COUNT(1) FROM T2";
                    int n2 = Convert.ToInt32(cmd.ExecuteScalar());
                    if (n2 != 1)
                         throw new Exception("COUNT(T2) != 1");
          // initialization          
          private static void init()
               executeCommands(
                    "CREATE TABLE T1 ( V1 VARCHAR2(100) )",
                    "CREATE TABLE T2 ( V2 VARCHAR2(100) )"
          // cleaning up
          private static void cleanup()
               try
                    executeCommands(
                         "DROP TABLE T1",
                         "DROP TABLE T2"
               catch
          // helper method executing some commands
          private static void executeCommands(params string[] queries)
               using (var connection = new OracleConnection(ConnectionString))
                    connection.Open();
                    OracleCommand cmd = connection.CreateCommand();
                    foreach (string query in queries)
                         cmd.CommandText = query;
                         cmd.ExecuteNonQuery();
It works fine mostly. But sometimes an exception is thrown at check method ("COUNT(T1) != 1" or "COUNT(T2) != 1"). So one of commands isn't enlisted into the transaction. And when I change commands to insert values into the same table (and also change check method), a deadlock sometimes occurs.
Where am I doing wrong?
P.S. There are no errors on Oracle 9.

The same question after a year: are you going to fix the issue?

Similar Messages

  • CRIO Doesn't Show Up In The Distributed Systems Manager

    All,
     Any idea why my cRIO wouldn't show up in the distributed systems manager? I'm running Real Time 3.2.1 and I've already deployed my shared variables. I can see the cRIO through MAX and with my project just fine.
    - Ken 

    Hi Ken,
    I have a couple of questions/things we can try:
    1.  How are you connected to the cRIO? (Crossover, switch, router with DHCP)
    2.  Are you able to manually add the cRIO by IP Address to My Systems?  (Right-click My systems, select Add Systems..., type in the IP Address and select OK.)
    3.  Are the shared variables hosted on the cRIO?  If not, do you see the Shared Variables in the Distributed System Manager?
    4.  Try enabling CPU Load Monitoring through the cRIO Target Properties in the LabVIEW Project (Right-click cRIO, select Properties, go to Miscellaneous and check Enable CPU Load Monitoring, deploy the settings and reboot the cRIO).
    5.  If you already had Distributed System Manager, does pressing F5 to refresh help? 
    Finally, I would like to know what version of Distributed System Manager/LabVIEW you are using.

  • You cannot use the application "System Preferences" with this version OS X

    You cannot use the application “System Preferences” with this version of Mac OS X.
    I received this error message when trying to run System Preferences (SP) for the first time after running the 10.5.1 update (from the download, not software update). After the update, I repaired permissions. Did another restart. Same.
    I reinstalled 10.5.1 update. Same message. Logged in as another user. No change.
    I removed the com.apple.systempreferences.plist from ~/library/preferences. No change, and it did not re-create the .plist file.
    Any ideas? No one else seems to be having this problem as far as I can tell.
    dkrockville

    I have had this problem with many applications after updating to 10.5.1, including
    System Preferences, Calculator, Preview. Tried repairing permissions, and other tips from this thread. The strange thing is, the actual Leopard applications seem to have actually vanished? I don't know if this is anything to do with Time Machine; Anyway, My fix was:
    Download Pacifist (if you don't already have it), locate the apps that you're having problems with on the Leopard install DVD, and copy them to the Applications Folder (Click on 'Replace Bundle')
    Problem Solved for Me!
    Hope this Helps!

  • HT2477 I have a new MacBook Pro which has Windows 7 installed so I have only ever used it as a PC,  I would like to use the apple system but was never shown how to do this and I cannot even work out how to switch it on .  If I just press power iI get wind

    I switch the power on on my MacBook Pro I get windows7
    this is no problem but I love my IPad and would like to use the apple system on my MacBook .
    CAn anyone tell me which keys I press to change from windows 7 to Apple most articles I have read tell you it is easy but not one says "firstly press x then press y and when you see c press v so I no idea how to do it,
    I am well educated but I am 75 so I do not understand the jargon but I am fairly good at using computers and I do like the app system.
    I Would be very pleased if someone can advise me
    best regards
    TOm

    Reboot, hold the option key down as soon as you hear the chime. When the Boot Manager appears select OSX instead of Windows.

  • I am using a mac mini 2011 an 3gs i phone 2010 macbook white 2008 and a new 2013 apple tv box. When i check info on the cloud I get 'upgrade your operating system to the latest. My question is is it possible to use the icloud system without an upgrade

    I am using a mac mini 2011 an 3gs i phone 2010 macbook white 2008 and a new 2013 apple tv box. When i check info on the cloud I get 'upgrade your operating system to the latest. My question is is it possible to use the icloud system without an upgrade

    iCloud requires OS X 10.7.2.

  • Error when using the variable System::ErrorDescription

    HI All,
    When I try to use the variable System::ErrorDescription I get the following error:
    The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.
    Do I need to declare it or it's a variable that always is available to get exceptions from the execution states?

    if this is in a Script Task then:
    - add the variable in the Script task property ReadOnlyVariables list
    - in the Script Code refer to it as
    string ErrorDesc = (string) Dts.Variables["System::ErrorDescription"].Value;
    Jan D'Hondt - SQL server BI development

  • About HR payroll posting FI in the distributed systems

    Hi All,
    I have a question about HR payroll post FI in the distributed system(both are Ecc6.0). There are difference In configuration between Ecc6.0 and lower version(like 4.70, 46C) ? 
    Best regards,
    Sap leaner

    Hi,
    Please see all the difference in service.sap.com
    Hope this helps,
    Reward points if helpful,
    Thank You,

  • Integration Directory Objects Transport Using the File System

    Hi
    I am trying to do the IR and ID Objects Transport Using the File system... I am able to Transport the IR Objects and IMport in to QA ... but when i try to Import ID objects its giving me the error...bcoz all the ID objects pointing to theSAP R/3 DEV system ( Interface Detremination, receiver determination ...)... do i have to config something in SLD ..so when i import the ID objects in to QA system it points to correct SAP R/3 QAS system...
    and we are using single SLD for all the DEV , QAS and PRD system
    SV
    Edited by: S V on Oct 15, 2008 4:08 AM

    Hi,
    You will have to configure transport targets like for different business systems in your dev environment, there shouls be corresponding Business systems in QUA environment. For more details refer the link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/a21e3e0987760be10000000a114084/frameset.htm
    Thanks!

  • I use the operating system Mac os x 10.10.2 and would like me like to purchase Adobe Photoshop Elements 13 am with but not sure because is specified in the system requirement only os x 10.9. Can you help me?

    I use the operating system Mac os x 10.10.2 and would like me like to purchase Adobe Photoshop Elements 13 am with but not sure because is specified in the system requirement only os x 10.9. Can you help me?

    Yes, it works. Download the trial and see for yourself. Adobe never updates the system requirements after any version is released, so that is what was available last Sept. when PSE 13 was released.

  • I can't use the distribute function in livecycle design?

    I can't use the distribute function in livecycle design?
    I have spent many hours designing this and the feature is not able to work it is greyed out.
    I am using adobe XI (not pro). What am I doing wrong?

    Hello,
    Do you want to make the form editable?
    If yes,
    To make this you need to Reader Extend the form by following steps.
    - Open the form in Acrobat Professional.
    - Click on Advanced option and then on Enable usage rights…here you can select the various usage rights to be enabled.
    - Save the file.
    Now you can distribute this form and users can fill in save for their records, print.
    -Vijay

  • I am an online student and the school uses the cloud system, however, the ipad will not allow me to post a reply, anyone got an answer as to what I need to do to change this?  Yes, the icloud is set up on my iPad.  It is frustrating, that I cant do this.

    I cannot respond to my online school who uses the cloud system and my cloud on my ipad is turned on and I have the proper IOS.  What is the problem?

    Unfortunately yes, though technology would never move on if it kept to older standards and did not strive to do more.
    The app store always gives you the option to use a previous version of the app IF it is available for your device.
    Sorry but you are stuck without new hardware.
    PJRS

  • 10.5.2: You cannot use the application "System preferences.app" with...

    Hello
    after (successfully) updating from 10.5.1 to 10.5.2, the System Preferences.app cannot be started. Either the application does not start (a silent error) or there is a message "You cannot use the application "System preferences.app" with this version of MacOS X." The version is 10.5.2, according to "About this Mac", while the application version is 3.5. The same happens when I attempt to open "Time machine preferences" using the new menu/icon on the bar.
    Any help is appreciated.
    Thanks in advance,
    Marinho.

    Thanks, I did that, but it didn't solve the problem.
    By the way, the application version (of System preferences.app) remained the same (old one). Then I removed the application to Trash (meaning to restore it later if required) and applied the update again (and a third time), but then a new System preferences.app was not installed and the older one has disappeared from the trash! What a mess this update turns out to be...
    Marinho.

  • Will the fm tuner work while I use the nikeplus system?

    Anyone have any knowledge on this?
    Also, It would be cool if you could switch to video while using the nikeplus system and not interrupt run.

    The answer is "sort of."
    If you turn on the FM radio first, THEN go to Nike+, select "Now Playing" and start your run, you can listen to the radio during your workout and even switch between preprogrammed radio stations. I did a 14 mile run this morning and listened to the radio the whole time.
    However, it's an awkward workaround, and my Nano crashed a few times while I was doing it. Plus, you can't switch between radio and your iTunes music, which it seems like you should be able to do.
    I love listening to radio while I run and bought the 5G Nano for this purpose. It's disappointing that Apple didn't do a better job of integrating the FM radio into their Nike+ system. All they need to do is add a radio function to the Nike+ music menu. Come on guys, it shouldn't be this hard.

  • Can I use the same trip number for several travelers?

    Hi everybody.
    This is my question... We need (in travel expenses) to use any field in order to group (add) several trips made for several travelers (in same dates).
    Expl: several travelers made the same trip (with different receipts and costs). We need to create a "supra-level" group (which could help our user to summarize, authorize, etc).
    I have made some tests changing the trip number assignment (in trip schema) to external one. The system seems not to have any problem if I assign the same trip number to several travelers (please, could you tell me if this is correct?).
    I´m not sure this could be the best solution, because I have one question... If I have travel request and travel expenses... can I assign external range numbers to the travel request? (how can I do it?).
    Please, could you tell me something about this? (if this is not correct, could you tell me if it´s possible to create a new field to do this?)
    Thanks!!!!!!

    Hi,
    As mentionned in an earlier response, you cannot assign the same trip number to multiple employees.
    If you are looking to group together similar claims based on the type of travel which was done, you can always use any of the following fields which can be made 'available' on the entry screen.  That is the 'Activity Type' or the 'Trip Type Specific' or the 'Trip Type Enterprise'.  By creating categories of types of travel, you can then use these values as selection parameters in your reports to isolate specific costs related to specific activities.
    For example, you know that many employees will be traveling for a specific conference and you want to be able to report on the total cost of that conference, you could create an Activity Type and ask employees to complete the field with the appropriate value when completing the claim.  Then you could create a report on that Activity Type only.
    Another option would be to use Internal Orders.  Create an internal order, have the employees assign their costs to the IO and then run a CO - IO report.
    Depending on how 'permanent' your employee groupings are, you could also use some fields on Infotype 17 to assign different employees to different employee groupings.  These employee grouping values are also available as selection parameters in the reports and can allow you to isolate groupings of individuals. 
    It all depends where you want to create the grouping....
    Hope this helps you somewhat...
    Regards,
    Roxanne Dore
    Travel & FI Consultant

  • How do I use the rating system for multiple raters?

    My wife, her sister, and I are all rating some photos I took a couple of days ago. Each of us, of course, has different favorites.
    I would like to record our different ratings in the LR3 rating system but can't see an immediately obvious way to do so. I thought of using the color labels--different color for each of us. But each photo will only take one color label. I could use the star ratings, one star for only one selection, two for two, etc. But that would not record who chose which. I need to know that.
    Has anyone had the same problem? If so, is there some rather obvious solution? I would think that it's not all that unusual for several folk to participate in a shoot, using one camera; and then to need some way to record their differing judgments on the photos in LR3.
    Any thoughts would be helpful. Thanks in advance,
    John Kendrick

    The rating system in LR3 is not really designed with that type of functionality in mind.  The "target Lightroom user" is an individual that uses LR to create a catalog of photographs which can be graded with a star rating based upon their opinion of the photograph.  The concept of seperate star ratings for multiple users doesn't really fit into that concept.  LR3, in general, is designed with a single photographer in mind... one that essentially uses the program by his/herself... so it has a bare minimum of 'group' functionality.
    It may be possible to find a plug-in that will enable star ratings by multiple users, but I've never heard of one before.
    If you really, really need this type of functionality (i.e. saving star ratings by multiple people), the only way to do it that I could think of would be to create multiple collections of the same shoot, each of which is filled with virtual copies of the original photos.  Each collection could hypothetically be called '08-03-2010 Bill Ratings'...'08-03-2010 Jill Ratings'... etc... etc.  Admittedly, such a workaround may very well be more trouble than its worth... that's just the only way I can think of that you might come close to achieving the functionality you're after.
    ***EDIT:  You beat me to it (VC idea) while I was typing this reply, Ian... wasn't trying to post redundant info...

Maybe you are looking for