Created
May 4, 2017 11:19
-
-
Save merthmagic/5b10a53dfd56eb68b88b7fe5cef45abb to your computer and use it in GitHub Desktop.
oracle 10g 在使用 odp.net 使用TransactionScope时提升为分布式事务的问题
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Data; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Transactions; | |
| using Oracle.ManagedDataAccess.Client; | |
| namespace OrclTransaction | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| using (var scope = new TransactionScope()) | |
| { | |
| //注意连接字,加了配置防止提升为分布式事务 | |
| using (var conn = new OracleConnection("Data Source=192.168.18.99/MSC_MANAGER;Persist Security Info=True;User ID=MSCMANAGER;Password=MSCMANAGER;PROMOTABLE TRANSACTION=LOCAL")) | |
| { | |
| conn.Open(); | |
| using (var cmd = conn.CreateCommand()) | |
| { | |
| cmd.CommandType = CommandType.Text; | |
| cmd.CommandText = @"select * from msc_users"; | |
| var rdr = cmd.ExecuteReader(); | |
| while (rdr.Read()) | |
| { | |
| Console.WriteLine(rdr["USER_ID"]); | |
| } | |
| Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier); | |
| } | |
| using (var scope2 = new TransactionScope()) | |
| { | |
| using (var cmd2 = conn.CreateCommand()) | |
| { | |
| cmd2.CommandType = CommandType.Text; | |
| cmd2.CommandText = @"select * from msc_users"; | |
| var rdr = cmd2.ExecuteReader(); | |
| while (rdr.Read()) | |
| { | |
| Console.WriteLine(rdr["LOGIN_NAME"]); | |
| } | |
| Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier); | |
| } | |
| scope2.Complete(); | |
| } | |
| } | |
| scope.Complete(); | |
| } | |
| Console.ReadKey(true); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment