Having issue establishing session from .Net app

Hello,
This issue has a major impact in our transactions…

A second company has been added to our Production env. And since then, one of our major .net app, which runs ever hour to perform transactions via BO, gives us an error as follows:
TV is one of our current site from original company
MAJZone is our application.

Ice.BLException: Access to site TV denied at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets) at Ice.Proxy.Lib.SessionModImpl.SetPlant(String newSite, String& siteName) at Ice.Core.Session.set_PlantID(String value) at MAJZone.Program.AutomaticMAJ(Session session, String plant) at MAJZone.Program.Main(String[] args)

(I was not the one who designed this, but it is working since 6 years ago)
I have found the code which is used to create the session:

static void Main(params string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


            var path = @"C:\Prog\Epicor102600\Client\Config\Polymos-Prod.sysconfig";

            if (args.Length > 0 && args[0].EndsWith(".sysconfig"))
                path = args[0];

            var session = new Ice.Core.Session("user", "pw", Ice.Core.Session.LicenseType.Default, path);

            AutomaticMAJ(session, "TV");

            AutomaticMAJ(session, "VD");

        }

        private static void AutomaticMAJ(Ice.Core.Session session, string plant)
        {
            session.PlantID = plant;
            using (var db = new EpicorDataContext(session))
            {
                try
                {
                    var extractor = new Extractor(db);
                    var processor = new Processor(db);

                    var todo = extractor.ExtractData();
                    processor.ProcessData(todo);                    
                }
                catch(Exception ex)
                {
                    EmailHandler.HandleException(ex, db, "Erreur lors de la mise à jour de zone automatique", "Usine : " + plant);
                }
            }            
        }

The new company was created at 14:45 today, and on the next run of the application (which is run on the server via Task manager) got the error of access denied.

I do not think it is a coincidence. I truly beleive that the new company is causing this. ( we have opened a ticket at Epicor about the issue)

But I was wandering if the call to the session creation can maybe be modified to address for which company we are trying to connect ? At least we could run the program without the error…

Thank you for your input.

Pierre

Try the below one.

Thank you I will try specify CompanyID

I noticed Licensetype you use GlobalUser I use Default.

What are the differences between the two? OK to leave as default?

Update about the issue.

The whole issue was that the username and password used in the .Net to establish the session was the same user in use when the new company was added. Then the user closed the Epicor. Well it saved the last company this user was in at the last use, which was the new one…, which did not contain the sites the .Net app was trying to use. Thus the site connection error.

We solved this by fluke (and later understood why… :wink: ) whe we went into Epicor under our current company and closed Epicor. (I did not test yet specifying the company in the connection, but I am sure it will avoid such issue)

So this is something to to keep in mind in the future when we will use both companies.

Pierre

Correct this will always be an issue in multi company environment
Your safest bet is to code in a session company switch in your app to ensure this ever happens again

Or make sure the account you are using doesn’t have access to the secondary company

1 Like

What we will end up do is the create a user just for the applications…instead of the master account…

Thanks Jose!