Plugin Scheduler Logs the error The transaction operation cannot be performed because there are pending requests working on this transaction

Problem

Plugins started or run by the Plugin Scheduler service may log the error "The transaction operation cannot be performed because there are pending requests working on this transaction" to the event log.

Causes

There are several possible causes of this error:

Solution

Make sure all use of the SqlCommand disposes correctly by using a using block, Make sure you always provide the SQLTransaction of the Manager class, and make sure you always close a SqlDataReader by performing a close in a finally block:

 

Modify the plugin(s) to observe and set a Critical Section flag - and to yield processing whilst that flag has been set - the following code shows how to do this.

In the case of plugins invoked on a schedule, this code should be placed right at the start of the Execute method of the ScheduledExecutionPlugin class - and the existing code placed in the try block.

In the case of an asynchronous hook, this should be placed at the start of the handler for that hook (e.g.: the OnFileImport method of a File Watcher), and the existing code placed in the try block.