Oracle上的TransactionScope和分布式事务协调器

时间:2012-02-24 15:45:42

标签: c# sql-server oracle distributed-transactions

我知道如何使用DTC和TransactionScope类跨两个MSSQL DB执行查询时实现分布式事务。是否有适用于Windows的Oracle和基于* nix的Oracle提供相同服务的基础结构选项,并且可以使用相同的代码,E.G。:

        try
        {
            using (var transactionScope = new TransactionScope(TransactionScopeOption.Required))
            using (var connection1 = new SqlConnection("{conectionString1}"))
            using (var connection2 = new SqlConnection("{connectionString2"))
            {
                var command = connection1.CreateCommand();

                command.CommandText = "insert into test values ('TEST') select @@identity";

                connection1.Open();

                var newRowId = command.ExecuteScalar();

                Console.WriteLine("Inserted new row in connection 1 with ID : {0}", newRowId);
                //transaction promoted on second connection open
                connection2.Open();

                command = connection2.CreateCommand();
                command.CommandText = "set identity_insert TEST on";
                command.ExecuteNonQuery();

                command.CommandText = string.Format("insert into test (Id, Text) values ({0},'TEST')", newRowId);
                command.ExecuteNonQuery();

                Console.WriteLine("Inserted new row in connection 2");

                transactionScope.Complete();
            }

            Console.WriteLine("Transaction commited");
        }
        catch (Exception)
        {
            Console.WriteLine("Transaction rolled back");
        }

0 个答案:

没有答案