0

I am trying to write c# code around opening a Sage 300 Connection using C#. I am using the Acccpac.Advantage DLL.

Here is my code

try
{
    sage300Session.Init(sessionHandle, appID, programName, appVersion);
    sage300Session.Open(_user, _ppswd, _companyID, DateTime.Today, 0);

    // Open a database link.
    sage300DbLink = sage300Session.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite);
}

The issue I am having is, no matter what I put in the password, the call to .Open seems to succeed. If I put an invalid user or companyID, I get errors as expected. (the connestion status seems to say open either way).

My question is - what is happening with the password that is doesn't seem to be used and 2- when I am through with what I am doing, is there a way to correctly close the connection?

The Accpac.Advantage dll is v 2.0.50727 and I am connecting to Sage 300 2014 environment.

jvoigt
  • 400
  • 4
  • 23
  • Can you show the code where you're creating your sage300Session object? Also, what are your variable's values for the .Init call? Are you connecting to live or test data and is security enabled for that database? –  Feb 27 '15 at 06:54

2 Answers2

0

As it turned out, the security setting was not enabled in the system database to require passwords to log in. Setting that "resolved" the issue and made the password be used. I never did find a way to disconnect from the session so I let it disconnect when I am done with the processing by having the connection go out of scope

jvoigt
  • 400
  • 4
  • 23
  • Both the DBLink and Session objects have a .close method. –  Mar 01 '15 at 01:08
  • I have looked at the dll for the API (AccPac.Advantage.Dll) There is not a close for either of those. Could you be referring to the AccpacCOMAPI ? And if so, is there a way to use the two in tandem? – jvoigt Mar 02 '15 at 14:44
  • Hmmm - my mistake. I would have expected you to be able to have access to the .Close methods. You might also try setting the object variable to Null. You could also run the DBSpy utility to confirm that your database connections are being closed when you destroy/free your object variable. I've never really used the two in tandem (I've not worked with the .Net interface at all). I've accessed the COMApi from .Net without much difficulty. –  Mar 02 '15 at 18:33
0

Actually, both Session and DBLink implement IDisposable and calling .Dispose (or the using keyword) would be enough to end the session. (I would have wanted to add this as a comment, but couldn't).