on 2020 Mar 30 12:23 PM
We are using SAP B1 10 PL00 on sql server 2014.
We write webservice application and publish it to IIS 10.
We are using DI API at web service.
When one user call method there is no problem(creates and update all documents)
But if more than one user calls method same time sql crashes and deadlock.
I need help, Please
int lRetCode = oCompany.Connect();
if (lRetCode != 0)
return false;
if (!oCompany.InTransaction)
oCompany.StartTransaction();
Documents doc = (Documents)oCompany.GetBusinessObject(BoObjectTypes.oPurchaseDeliveryNotes);
doc.CardCode = cardCode;
// .......
lRetCode = doc.Add();
if (lRetCode != 0)
return false;
else
{ //....... do some update }
if (oCompany.InTransaction) oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
Request clarification before answering.
Hi,
Try using an C# lock-statement around your transaction.
It will prevent using the COM object from parallel requests and will instead halt the second request until the first request is done.
Depending on how the class is instantiated the lockObject may need to be static.
public class WebService
{
private readonly object lockObject = new object();
public void MyMethod()
{
lock (lockObject)
{
var lRetCode = oCompany.Connect();
if (lRetCode != 0)
return;
if (!oCompany.InTransaction)
oCompany.StartTransaction();
// My code
if (oCompany.InTransaction)
oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
}
}
}
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
17 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.