IBM MQQueueManager не откатывается под TransactionScope C # - PullRequest
0 голосов
/ 10 июля 2019

Мой код более высокого уровня выполняет следующие действия:

  1. Получает сообщение из таблицы SQL.
  2. Помещает его в очередь IBM.
  3. Обновляет SQLсообщение таблицы отправлено.

Эти шаги выполняются в TransactionScope на C #.

Когда из кода выдается исключение (пыталось сделать это явно) в качестве одного из тестовых случаев,TransactionScope откатывает обновление SQL, но сообщение в очереди IBM не откатывается.

На веб-сервере включен DTC.

#region Send Message                            
                        for (int n = 0; n < rowIds.Count; n++)
                        {
                            using (TransactionScope scope = new TransactionScope())
                            {
                                try
                                {
                                    Transaction.Current.TransactionCompleted += Current_TransactionCompleted;
                                    using (var wmq = new WmqConnection())
                                    {

                                        byte[] msgId = wmq.WriteMsg(rowsData[n]);

                                        //writes to the text file
                                        writer.WriteLine("MessageID:" + BitConverter.ToString(msgId) + " ||RaInterfaceDataID:" + rowIds[n] + " ||Message:" + rowsData[n]);

                                        using (SqlConnection connection2 = ConnectionFactory.GetConnection())
                                        {
                                            #region Mark Interface Data Complete
                                            connection2.Open();
                                            sqlCommand = new SqlCommand("Update InterfaceData Set Status = 'C' Where IntrfceDtaID = " + rowIds[n] + " and Status = 'F'", connection2);
                                            rowsEffected = sqlCommand.ExecuteNonQuery();
                                            if (rowsEffected != 1)
                                                throw new TransactionAbortedException();
                                            #endregion
                                        }

                                        throw new TransactionAbortedException();

                                    }

                                    //scope.Complete();
                                }
                                catch (TransactionAbortedException tex)
                                {
                                    throw tex;
                                }

                            } //transaction scope ends

                            n++;
                        } //send message ends

// Код дляотправить сообщение (другой метод)

ConnectMQ();
                MQConnectOptions mco = new MQConnectOptions();
                queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                queueMessage = new MQMessage();
                queueMessage.WriteString(inputMsg);
                queueMessage.Format = MQC.MQFMT_STRING;
                queuePutMessageOptions = new MQPutMessageOptions();
                queuePutMessageOptions.Options = MQC.MQPMO_SYNCPOINT; 
                queue.Put(queueMessage, queuePutMessageOptions);
                return queueMessage.MessageId
...