数据库重启后无法登记分布式事务

时间:2013-02-20 10:51:15

标签: oracle ado.net oracle11g odp.net msdtc

您好,我在数据库重启后登记到分布式事务有问题。

我的环境:

  • Windows 7 x64 SP1;
  • Oracle Database 11g Express Edition
  • ODP.NET 4.112.3.0

我的节目:

const string connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=LOCALHOST)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));User Id=system;Password=sasa;";

static void Main(string[] args)
{
    using (TransactionScope scope = new TransactionScope())
    {
        while (true)
        {
           using (OracleConnection connection = new OracleConnection(connectionString))
           {
               try
               {
                   connection.Open();
                   Console.WriteLine("Connection opened");
               }
               catch (Exception ex)
               {
                   Console.WriteLine(ex.Message);
               }
           }
           Thread.Sleep(1000);
        }
    }
}

应用程序启动后一切正常。当我开始停止数据库时,我得到NRE并且有一些异常告诉我数据库关闭正在进行中。再次启动后,我收到错误 - 无法登记分布式事务。打开连接不再打印。

输出:

Connection opened
Connection opened
Connection opened
Connection opened
Connection opened
-- here I'm stopping database
ORA-12518: TNS:listener could not hand off client connection
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
-- here database is stopped I suppose
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
-- here I'm starting database again
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
ORA-1033: ORACLE initialization or shutdown in progress
Unable to enlist in a distributed transaction
Unable to enlist in a distributed transaction
Unable to enlist in a distributed transaction
Unable to enlist in a distributed transaction
Unable to enlist in a distributed transaction
...
  • 这种行为的原因是什么?
  • 如何诊断发生了什么?

1 个答案:

答案 0 :(得分:1)

您的测试无效。您正在循环内部单个事务的上下文。当数据库关闭时,任何正在进行的分布式事务都将中止。您的循环正在尝试在已经死亡的事务下启动新连接。

我不确定您要测试的确切内容,但在while循环中移动TransactionScope应该可以修复它。