Sage 300 Newsletter – April 2016
Keeping You Up-To-Date With Information About Sage 300
The Basics of Connecting to Sage 300 Using the API
When integrating with Sage 300, the first step is to establish a connection. A valid connection will allow your system to read and write data from Sage 300 per your particular needs. There are two basic ways to establish a connection: programmatic or implementing Signon manager. Depending on the type and specifications of your integration, you would choose one method over the other.
You would use Signon Manager if you have an integration that requires a user to interactively sign into Sage 300. There are a number of reasons to use this method. For example, if you wanted to track which users were creating transactions in Sage 300, you would have them log in using Signon Manager. Another reason would be if you wanted to make your UI company independent. You would have the user log in using Signon Manager which includes choosing which company to log into. In fact, Signon Manager is the same interface used by Sage 300, so users will have a familiar login screen in your application. You don’t have to write any authentication routines, it is all built into the control.
To use Signon manager in your application, you will need to add a reference to it. Here is an example of adding the reference in Visual Studio:
Note that it will also add a reference to the “Accpac COM API” if you do not have it because there is a dependency.
After adding a reference, you can instantiate Signon manager in code. Here is a VB.NET example:
Using the Signon method will pop up the login screen Sage 300 users are accustomed to:
Once signed in, the code above displays the company ID and name in the title:
Once you have your session via the Signon manager, you can open a DB link and from there you can interact with the company’s data. As you can see from the sample code above, in just a few lines of code you can be on your way to integrating with Sage 300.
You would use this method of connecting to Sage 300 if your integration did not require any user interaction. Your application would need to store the user name, password and company ID that you will be connecting to. Typically, you would create a generic user or use the “Admin” user for this method. The same principles apply as the Signon manager method. You would need to initialize a session object, then login, then establish your DB link. First, you need to add a reference to the Accpac COM API. Here is an example of adding the reference in Visual Studio:
Here is an example of establishing a connection using VB.NET:
Using the “Open” method and supplying the credentials will let you log into Sage 300 programmatically.
As you can see, there are different methods to connect to Sage 300 and depending on the integration, you will choose the more appropriate one. If you need assistance with any integration needs, our team at Net at Work will be happy to help.