web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

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

(0) ShareShare
ReportReport
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

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 179 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 61 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans