Добро пожаловать в форум, Guest  >>   Войти | Регистрация | Поиск | Правила | В избранное | Подписаться
Все форумы / Microsoft SQL Server Новый топик    Ответить
 xact_state() = -1 при cast(@xml as xml(XSD))  [new]
barabas
Member

Откуда:
Сообщений: 144
Всем привет!

Подскажите плз, почему сиквел жестко рубит транзакцию при попытке проверки XML-ки на соответствие XSD-схеме.

У меня стоит задача обработать в CATCH ситуацию несоответствия XML-ки XSD-шке.

DECLARE 
  @errorMessage varchar(800),
  @messageBody nvarchar(max), 
  @actions xml(dbo.actions) -- Типизированная xml

  SET @messageBody = '...' 
		
  BEGIN TRAN

  BEGIN TRY

    SELECT xact_state() as xact_state1
    SET @actions = cast(@messageBody as xml)
    SELECT xact_state() as xact_state2
                          
  END TRY
        
  BEGIN CATCH        

   SELECT xact_state() as xact_state3
          
   SET @errorMessage = ERROR_MESSAGE()
 			    
   INSERT INTO dbo.Garbage (errorText,messageBody)
   VALUES (@errorMessage, @messageBody)
                    
  END CATCH


  BEGIN TRY
    WHILE @@TRANCOUNT > 0
      COMMIT TRAN 
  END TRY
  BEGIN CATCH
    ROLLBACK TRAN
  END CATCH



xact_state1
-----------
1

(1 row(s) affected)

xact_state3
-----------
-1

(1 row(s) affected)

Msg 3930, Level 16, State 1, Line 41
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
13 янв 12, 00:38    [11896342]     Ответить | Цитировать Сообщить модератору
 Re: xact_state() = -1 при cast(@xml as xml(XSD))  [new]
barabas
Member

Откуда:
Сообщений: 144
вот нашел ...

BOL
Uncommittable Transactions and XACT_STATE
If an error generated in a TRY block causes the state of the current transaction to be invalidated, the transaction is classified as an uncommittable transaction. An error that ordinarily ends a transaction outside a TRY block causes a transaction to enter an uncommittable state when the error occurs inside a TRY block. An uncommittable transaction can only perform read operations or a ROLLBACK TRANSACTION. The transaction cannot execute any Transact-SQL statements that would generate a write operation or a COMMIT TRANSACTION. The XACT_STATE function returns a value of -1 if a transaction has been classified as an uncommittable transaction. When a batch finishes, the Database Engine rolls back any active uncommittable transactions. If no error message was sent when the transaction entered an uncommittable state, when the batch finishes, an error message will be sent to the client application. This indicates that an uncommittable transaction was detected and rolled back.
13 янв 12, 01:44    [11896487]     Ответить | Цитировать Сообщить модератору
Все форумы / Microsoft SQL Server Ответить