测这个东西其实是由生产环境数据库报错,ORA-14450错误。

测试结果是:

1)使用transactionscrope时,数据库连接打开需在scrope内打开;

2)TransactionScopeOption.Suppress 是无事务(原有同事非得说是原子事务,证明给他看)。

不多说了,代码上来:

create global temporary table TMP_TEST
(
COL1 VARCHAR2(200)
)
on commit delete rows;

由于是使用的是Oracle 所以添加引用System.Date.OracleClient,且添加System.Transactions的引用;

OracleConnection con = new OracleConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["MB.MBERP"].ConnectionString; try
{
con.Open(); #region DBTransaction
var tran = con.BeginTransaction(); OracleCommand cmd1 = new OracleCommand("insert into TMP_TEST values('" + DateTime.Now + "')", con, tran);
var result = cmd1.ExecuteNonQuery(); OracleCommand cmd2 = new OracleCommand("select COL1 from tmp_test", con, tran);
var t = cmd2.ExecuteOracleScalar(); tran.Commit();
con.Close();
Console.WriteLine("受影响的行数:" + result + "||当前临时表数量:" + t); #endregion
using (TransactionScope scop1 = new TransactionScope())
{
OracleCommand cmd4 = new OracleCommand("insert into TMP_TEST values('" + DateTime.Now + "')", con, tran);
con.Open();
var result3 = cmd4.ExecuteNonQuery();
con.Close();
using (TransactionScope scop = new TransactionScope(TransactionScopeOption.Required))
{
OracleCommand cmd = new OracleCommand("insert into TMP_TEST values('" + DateTime.Now + "')", con, tran);
con.Open(); var result2 = cmd.ExecuteNonQuery(); OracleCommand cmd3 = new OracleCommand("select COL1 from tmp_test", con);
var t2 = cmd3.ExecuteOracleScalar();
Console.WriteLine("2受影响的行数:" + result + "||当前临时表数量:" + t2); OracleDataAdapter da = new OracleDataAdapter("select * from TMP_TEST", con);
DataTable dt = new DataTable();
da.Fill(dt);
Console.WriteLine("3受影响的行数:" + result2 + "||当前临时表数量:" + dt.Rows.Count);
scop.Complete();
}
}
con.Close();
}
catch (Exception)
{ throw;
}

第二个transactionscrope 使用默认的即required结果为

第二个transactionscrope 使用RequiresNew时结果为

第二个transactionscrope 使用suppress时结果为

由此可以看出测试结果。

另:由上解释 如果con在transactionscrope外打开时,临时表插入后查询,将无任何数据。

此仅作为笔记先记录下来,后续分析原因。

TransactionScrope的更多相关文章

  1. TransactionScrope 2

    继上一篇文章TransactionScrope 在做相应的变动时,发现可以重现ORA-14450错误,如: List<Thread> ls = new List<Thread> ...

随机推荐

  1. 将html导出到excel或word

    本质是将html写成word或excel支持的html格式. 如何将html写成word或excel支持的格式? 只需打开计算机上任意一个word或excel文档,打开文件->另存为,选择文件类 ...

  2. AngularJs练习Demo1

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  3. .net 2.0中半角全角错误的解决办法

    VS2005中.net 2.0编译报错如下所示:'System.Windows.Forms.ImeMode' does not contain a definition for 'OnHalf'.只需 ...

  4. 对arm指令集的疑惑,静态库运行,编译报错等问题

    转载自http://www.jianshu.com/p/4a70aa03a4ea?utm_campaign=hugo&utm_medium=reader_share&utm_conte ...

  5. linux中的fork函数的基本用法

    代码: #include <iostream> #include <string> #include <cstdio> #include <unistd.h& ...

  6. C/C++中的常成员函数

    代码: #include <iostream> using namespace std; class A{ public: void func1(){ cout<<" ...

  7. CODEVS 1066/洛谷 P1514引水入城

    1066 引水入城 2010年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description 在一个遥远的国 ...

  8. 如何debug android cts

    启动和关闭ADB服务(adb start-server和adbkill-server) 经作者测试,模拟器在运行一段时间后,adb服务有可能(在Windows进程中可以找到这个服务,该服务用来为模拟器 ...

  9. C语言多维数组的地址

    设有整型二维数组a[3][4]如下: 0   1   2   3 4   5   6   7 8   9  10  11  它的定义为:     int a[3][4]={{0,1,2,3},{4,5 ...

  10. git:fatal the current branch master has no upstream branch

    git push的时候发生上述错误. git push -u "resp" master resp为git仓库的“地址” reference中由解决方案 http://blog.c ...