Open a sage 300 AccPac DBLink Connection to a session

1.6k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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

3
On

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