Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Unanswered

Dynamics 365 CE (on-premise 9.1.15.32) Async Service Issue on Bulk Workflow Execution

Posted on by 10

Hello,

we have an issue since a long time that as soon as we run a Workflow in Bulk we get following error:

Exception type: Microsoft.Crm.CrmException
Message: ValidateClosed - Db GetCreateConnection() should be closed on End
bei Microsoft.Crm.Workflow.Services.UpdateActivityService.Execute(ActivityContext executionContext, UpdateEntity updateEntity)
bei System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
bei System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
-- End stack trace --

Sometimes also:

The operation or property SqlTransaction is not valid in the context without calling OnBeginRequest first Line:0

And

InvalidOperationException The connection was not closed. The connection's current state is open

This happens for every single entity we have, but only if you run a workflow for multiple entries at once.

If i do it step by step it works every single time.

After spending some time on Searching the internet for this issue i found out that this issue appears if you use global variables inside Plugins.

But the strange issue is we don't do that.

Here is a example of Post Plugin for account entity:


using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Globalization;
using CrmSvcUtil;
using System.Diagnostics;

namespace PostAccountUpdate
{
/// <inheritdoc />
/// <summary>
/// Base class for all plug-in classes.
/// </summary>
public class PostAccountUpdate : IPlugin
{
/// <summary>
/// Plug-in context object.
/// </summary>
protected class LocalPluginContext
{
/// <summary>
/// Helper object that stores the services available in this plug-in.
/// </summary>
/// <param name="serviceProvider"></param>
internal LocalPluginContext(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
}

/// <summary>
/// Writes a trace message to the CRM trace log.
/// </summary>
/// <param name="message">Message name to trace.</param>
internal void Trace(string message, ITracingService TracingService, IPluginExecutionContext PluginExecutionContext)
{
if (string.IsNullOrWhiteSpace(message) || TracingService == null)
{
return;
}

if (PluginExecutionContext == null)
{
TracingService.Trace(message);
}
else
{
TracingService.Trace(
"{0}, Correlation Id: {1}, Initiating User: {2}",
message,
PluginExecutionContext.CorrelationId,
PluginExecutionContext.InitiatingUserId);
}
}
}

/// <inheritdoc />
/// <summary>
/// Main entry point for he business logic that the plug-in is to execute.
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "CrmVSSolution411.NewProj.PluginBase+LocalPluginContext.Trace(System.String)", Justification = "Execute")]
public void Execute(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}

// Construct the local plug-in context.
LocalPluginContext localcontext = new LocalPluginContext(serviceProvider);
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
string relationshipName = String.Empty;

IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
Log.CRMService = service;

try
{

........

Does anyone have an Idea how to fix this?

Thanks for help

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans