代码如下
try { using (TransactionScope scope=new TransactionScope()) { AddForSqlserver("insert into test values (1,'aaa')"); AddForOracle("insert into test values ('001','aaa',1)"); AddForOracle("insert into test values ('001','aaa')"); scope.Complete(); } } catch (Exception ex) { }
执行难第三条sql 会插入失败,sqlsqlver的数据时没有被插入的,但是第二条oracle的数据确被插入了。
private void AddForOracle(string sql) { using (var conn = new OracleConnection(str)) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = sql; cmd.CommandType = CommandType.Text; try { int n = cmd.ExecuteNonQuery(); if (n
- 7 回答
- 0 关注
- 944 浏览
添加回答
举报
0/150
提交
取消