当前事务无法提交,也无法支持写入日志文件的操作

时间:2017-11-24 10:50:14

标签: sql sql-server-2014

我的下面的代码是我们在清除程序中使用的。直到昨天我们没有任何问题,但今天突然失败,错误。“当前事务无法提交,不能支持写入日志文件的操作”

我在交易期间没有写任何东西,那么为什么会出现这样的错误,是因为数据。

我应该在临时表上添加索引还是在删除数据时使用子选择而不是连接来修复它?我们不能在我们的内部重现这一点,因为它只是在生产中。

WHILE @RetryCount< = 3 AND @Success = 0 开始     开始尝试

    -- Remove potential orphan records from various tables related to the .NET instances table
        BEGIN TRAN
        CREATE TABLE #WFEngineQueueCompleteOrphanInstanceTable  
        (
            ID uniqueidentifier NOT NULL
        )

        -- Locate records in the SXAVWFWorkflowEngineQueueComplete table that have no associated records in the Instances table
        INSERT INTO #WFEngineQueueCompleteOrphanInstanceTable 
            SELECT TOP (@RowsPerRun) InstanceUID 
                FROM SXAVWFWorkflowEngineQueueComplete AS q WITH (nolock)
                WHERE NOT EXISTS ( select 1 from [System.Activities.DurableInstancing].[InstancesTable] as i  with (nolock)
                                    where i.id = q.InstanceUID)
                AND CreatedWhenUTC <  @ChkDate
                AND InstanceUID is not null

        -- Perform the delete
        DELETE q FROM SXAVWFWorkflowEngineQueueComplete q
        JOIN #WFEngineQueueCompleteOrphanInstanceTable t ON t.ID = q.InstanceUID

        -- Drop the temporary table
        DROP TABLE #WFEngineQueueCompleteOrphanInstanceTable

        IF @@ERROR <> 0
        BEGIN
            RAISERROR ('Error purging orphan records from SXAVWFWorkflowEngineQueueComplete', 16, 1)
            ROLLBACK TRAN
            RETURN
        END 
        COMMIT TRAN

BEGIN CATCH

      SELECT  ERROR_NUMBER() AS [Error Number],
      ERROR_MESSAGE() AS [ErrorMessage];     

      -- Now we check the error number to 
      -- only use retry logic on the errors we 
      -- are able to handle.
      --

      IF ERROR_NUMBER() IN (  1204, -- SqlOutOfLocks
                              1205, -- SqlDeadlockVictim
                              1222, -- SqlLockRequestTimeout
                              3960  -- Snapshot Conflict
                              )
      BEGIN
            SET @RetryCount = @RetryCount + 1  

            WAITFOR DELAY '00:00:05'  --let the blocking transaction finish
      END 
      ELSE    
      BEGIN
            -- If we don't have a handler for current error
            -- then we throw an exception and abort the loop
            THROW;

END     END CATCH

0 个答案:

没有答案