Exception on nWrite in CI_Item in C#

Experts,

I have a small app that writes to CI_Item. It has been working with no issues in Sage 100 v2017 Premium for my client in a Sage Server / Terminal Server setting. Now they are on v2020 Premium in the same setup (new servers), but we are running into issues on the Terminal Server (it works fine when I run the app on the Sage server).

Here is what is going on:

The app logs into the Sage company that needs to be updated, and that works. It is supposed to update a few Standard fields and UDFs in CI_Item (all of these fields can be modified in the UI by the user without any issues). The program is written to loop through the items and update one at a time.

Now when I run this from the TS, then the nWrite throws the following exception on the first line:

"Object Reference not set to an instance of an object."

The other items in the loop throw the following error on nWrite:

"Exception has been thrown by the target of an invocation."

I can see, that the values for the first line get actually updated.

The program is written in a way that you can hit a retry button to trigger the import for items that failed. Now when you click this button, the first item change will NOT throw an exception, but the others will. You can trigger the retry, and the first one will always make it.

That doesn't make sense, does it? Especially since this works properly from the Sage server. I can also see that the time it takes to build the connection into Sage/run the update is a few seconds. Not sure if there might be a connection issue. It worked fine in v2017 in the same virtual server environment.

Here is the section of the codes that fails. It's not getting to the retVal part where I would manually throw the exception.

retVal = (int)oItem.InvokeMethod("nWrite");
sLastFunction = "nWrite";
if (retVal == 0)
{
    sErrorMsg = Regex.Replace(oItem.InvokeMethod("sLastErrorMsg").ToString(), "'", "");
    throw new System.Exception("Error obj.Write.");
}
else if (retVal == 1)
{
    nSuccess++;
    row.SetField("Status", "Updated");
    row.SetField("UDF_SP_CHANGEDATE", DateTime.Now);
    row.SetField("UDF_SP_CHANGEUSER", _sCurrentSageUser);
}
retVal = (int)oItem.InvokeMethod("nClear");

Any ideas are appreciated!

Best,

B.

Parents
  • Very odd behavior. 

    When the workstation was upgrade, was the terminal server placed into install mode before installing the sage 100 workstation and then placed in execute mode after all software was installed?

    Is the pvxcom.exe process crashing or terminating prematurely after the first write?

  • in reply to David Speck

    I can see the PVXCOM in the Task Manager until after the failed results are rendered in the UI of my app. I don't know what the delay is for the Task Manager to remove a process that has been shut down.

  • in reply to BillyVanilli

    I wanted a help from you. Recently I got a request from one of my clients to import data in Sage 100 in real time.

    Do you know what is the best way to achieve this?

    FYI, I was thinking about using Sage 100 BOI. I was looking at your example code above and I think this can help me.

    Can you share some steps on how to using SAGE 100 BOI with C# and some sample code if possible?

  • in reply to ShubhamP

    Talk with your Sage partner about this: "import data in Sage 100 real time".  Depending on what kind of data you want to bring in, and whether it needs to come in over a web connection, the answer is not quick.

Reply
  • in reply to ShubhamP

    Talk with your Sage partner about this: "import data in Sage 100 real time".  Depending on what kind of data you want to bring in, and whether it needs to come in over a web connection, the answer is not quick.

Children
No Data