Sage 2017 - 64A can't login through C# App.

SOLVED

Wrote simple app to simulate login into Sage 300 in C#

i can query the company names... but when i try to actually use a password and login user it gives me Invalid Signon Information error message, anyone know what i'm doing wrong?

session = new ACCPAC.Advantage.Session();
session.Init("", "XX", "XX1000", "64A");
foreach (Organization org in session.Organizations)
{
if (org.Type.ToString() == "Company")
{
Company.Items.Add(org.Name);
}
Info.Text += "Company ID: " + org.ID + " Name: " + org.Name + " Type: " + org.Type + "\r\n";
}

session.Open("BOB", "somePassword", Company.Text, DateTime.Today, 0);
mDBLinkCmpRW = session.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);

Parents
  • 0

    The basic code is:

    using ACCPAC.Advantage;
    
    Session accpacSession;
    DBLink mDBLinkCmpRW;
    View csQry;
    
    private int OpenDBAndComposeViews(string psCompany)
    {
        accpacSession = new Session();
        accpacSession.Init("", "XY", "XY1000", "64A");
    
        try
        {
            accpacSession.Open("ADMIN", "ADMIN", psCompany, DateTime.Today, 0);
            mDBLinkCmpRW = accpacSession.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite);
            
            /*
            Compose views here
            */
            csQry = mDBLinkCmpRW.OpenView("CS0120");
            
            return 0;
        }
        catch (Exception ex)
        {
            LogHelper.Log(LogTarget.EventLog, "Unable to connect to Sage. Message: " + ex.Message);
    
            return 1;
        }
    }
    
    private void CloseSageConnectionAndCleanup()
    {
        if (csQry != null) csQry.Dispose();
        if (mDBLinkCmpRW != null) mDBLinkCmpRW.Dispose();
        if (accpacSession != null) accpacSession.Dispose();
    }
    
    private void DoSomething()
    {
        string sDBName = "";
        string sCompanyName = "";
        
        try
        {
            csQry.Browse("select ORGID, CONAME from CSCOM", true);
            csQry.InternalSet(256);
    
            while (csQry.Fetch(false))
            {
                sDBName = csQry.Fields.FieldByName("ORGID").Value.ToString().Trim());
                sCompanyName = csQry.Fields.FieldByName("CONAME").Value.ToString().Trim();
            }
            
            Console.WriteLine("DB Name: " + sDBName);
            Console.WriteLine("Company Name: " + sCompanyName);
        }
        catch (Exception ex)
        {
            LogHelper.Log(LogTarget.File, $"Error: {ex.Message}");
        }
    }

    This isn't a fully working piece of code but it gives you the basis of what you need. If you still have problems, let us know.

  • 0 in reply to Vega

    Thank you so much for the code,

    but the exception is as follows:

    Invalid Signon Information

    Make sure to supply the correct User ID and Password

  • 0 in reply to BOB2023

    Have you got the Sage .NET DLLs installed on your machine?

  • 0 in reply to Vega

    Yes i did, installed properly.

  • 0 in reply to BOB2023

    Feels like a permissions thing. Run the app as administrator

  • 0 in reply to Vega

    yeah i did, nothing same problem.  weird. 

  • +1 in reply to BOB2023
    verified answer

    Out of curiosity, what happens if you hard code all of the values, including the org id?

    Also can you change your app prefix from XX to XY?

Reply Children