I am trying to add a new UD101A record using a BPM, when executing the update statement I receive an error message in the server event viewer saying:
Ice.Common.EpicorServerException: BPM runtime caught an unexpected exception of ‘EntityException’ type.
See more info in the Inner Exception section of Exception Details. —> System.Data.Entity.Core.EntityException: The underlying provider failed on EnlistTransaction. —> System.Data.SqlClient.SqlException: The operation failed because the session is not single threaded.
Here is the code:
var svcUD101 = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD101SvcContract>(Db,true);
bool v_Bool = false;
var v_UD101 = (from ttUD101 in ttUD101
select ttUD101).FirstOrDefault();
if (v_UD101 != null)
{
Int32 v_FromPallet = Convert.ToInt32 (v_UD101.ShortChar04);
Int32 v_ToPallet = Convert.ToInt32 (v_UD101.ShortChar05);
string v_Key1 = v_UD101.Key1;
string v_Key2 = v_UD101.Key2;
string v_Key3 = v_UD101.Key3;
string v_Key4 = string.Empty;
string v_Key5 = string.Empty;
var tsUD101 = svcUD101.GetByID (v_Key1, v_Key2, v_Key3, v_Key4, v_Key5);
// svcUD101.GetList (“UD101A”, 0, 0, out v_Bool);
foreach (var v_PartLot in (from PartLot in Db.PartLot
where PartLot.Company == Session.CompanyID
&& PartLot.PartNum == v_UD101.Key2
select PartLot))
{
if (Convert.ToInt32 (v_PartLot.LotNum) >= v_FromPallet && Convert.ToInt32 (v_PartLot.LotNum) <= v_ToPallet)
{
svcUD101.GetaNewUD101A (ref tsUD101, v_Key1, v_Key2, v_Key3, v_Key4, v_Key5);
foreach (var v_NewUD101A in (from NewUD101A in tsUD101.UD101A
where NewUD101A.RowMod == "A"
select NewUD101A))
{
PublishInfoMessage("Key1 " + v_Key1, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "Company", "Update");
v_NewUD101A.Key1 = v_Key1;
v_NewUD101A.Key2 = v_Key2;
v_NewUD101A.Key3 = v_Key3;
v_NewUD101A.Key4 = v_Key4;
v_NewUD101A.Key5 = v_Key5;
v_NewUD101A.ChildKey1 = v_PartLot.LotNum;
v_NewUD101A.CheckBox01 = false;
v_NewUD101A.CheckBox02 = false;
}
svcUD101.Update (ref tsUD101);
}
}
}
Any sharp eyes to see what I am doing wrong? It is working when I comment out the update statement, but nothing is saved of course.