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.

  • 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

    Good points David and thanks for the reply. I believe that for most programs it isn't necessary anymore to put a TS into install mode, but I always do it anyway. So the answer to your first question is yes. I will do some tests with the Task Manager open to see what happens to the pvxcom.exe.

    Is there a way to set a timeout time. The same way as you would for scripts?

  • in reply to BillyVanilli

    You may need to have some way to halt the program after the nWrite that causes the message saying "Object Reference not set to an instance of an object.".  If you are currently writing to a log, try just inserting a message box/prompt or something that will suspend it at that point.

  • 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 David Speck

    I put a MsgBox before and after the nWrite. The PVXCOM object is still available when the Before-MsgBox comes up, and it doesn't go away when I wait. Since the nWrite throws the exception, I don't make it to the second MsgBox.

    That confirms, that the error occurs during the nWrite call (after the data has actually been written. Not sure where to go from here. I bet that it is something environmental. As mentioned in my initial post, the error only happens on the Terminal Server(s) and not from the Sage server itself.

    I changed the script timeout to see if that makes a difference, but it didn't.

  • 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.

  • in reply to ShubhamP

    I agree with Kevin. There are solutions available to connect Sage with webshops, Amazon, logistics providers, etc. It makes sense to discuss with your Sage partner if there is a solution available that meets your needs before you reinvent the wheel.

    You can use BOI to push data into Sage. In C#, I am using a Dispatch Object class for the interactions with Sage. There is lots of information on this forum about this. You will need to know the Sage data structure and some of the "under the hood" behavior to successfully create an implementation. For that, you should involve your reseller as well.

  • in reply to BillyVanilli

    Thanks guys for your feedback.