0

嗨,我在数据库重新启动后登记分布式事务有问题。

我的环境:

  • 带有 SP1 的 Windows 7 x64
  • Oracle 数据库 11g 快捷版
  • 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
...
  • 这种行为的原因是什么?
  • 如何诊断发生了什么?
4

1 回答 1

1

您的测试无效。您正在单个事务的上下文中循环。当数据库关闭时,任何正在进行的分布式事务都会中止。您的循环正试图在该已死事务下建立一个新连接。

我不确定您要测试的确切内容,但将 TransactionScope 移动到 while 循环内应该可以解决它。

于 2013-02-22T00:08:55.960 回答