4D QuickBooks Integrator: Connection Lifespan


Details three different lifespan options of connections between the components and QuickBooks.

There are three connection methodologies that can be used when connecting an application to QuickBooks. The type of the connection to use depends on the needs of the application.

Non-Persistent Connection
This is the type of connection our components use by default. When a method is called, a connection to QuickBooks is opened, data is sent and received, and the connection is closed immediately.

This type of connection is the least efficient, especially if QuickBooks is closed. If closed, QuickBooks will launch as a background process, which will typically take an average sized company file about 10 seconds to load. This connection type is fine if for single transactions, but should be avoided otherwise.

Persistent Connection For Each Individual Component
This type of connection will allow a persistent connection with QuickBooks to be opened. First, a connection to QuickBooks is opened using the OpenQBConnection method. After this, the Get, Update, or Add methods can be called multiple times. The connection will remain open until the CloseQBConnection method is called.

This is much more efficient, but you can only use this connection with the same component. If you are switching between components, it loses efficiency because the connection must be closed with one component before opening a connection with another component.

Example: (adding multiple customers to QuickBooks)

Customer cust1 = new Customer(); cust1.QBConnectionString = "connection string"; cust1.OpenQBConnection(); // Fill the customer object with new customer information. cust1.Add(); // Repeat for as many customers as needed. cust1.CloseQBConnection();

Persistent Connection For All Components
This type of connection takes advantage of the 4D Connector for QuickBooks application to keep a connection to QuickBooks open for any component to use for as long as it is needed. 4D Connector for QuickBooks is a distributable utility included with the QuickBooks Integrator that allows applications to connect to QuickBooks remotely. Additional information on the 4D Connector can be found here: 4D Connector.

The 4D Connector for QuickBooks application opens a COM connection to QuickBooks, and contains an embedded HTTP web server that listens on a specified port (default 8166). The application can communicate with QuickBooks through the 4D Connector just as it normally would, but all communications are happening over a single connection to QuickBooks. Because the 4D Connector is used to hold the connection to QuickBooks open, all that is required is to call OpenQBConnection with the first component being used, and CloseQBConnection with the last component being used. This eliminates the overhead of opening and closing a connection to QuickBooks multiple times.

This is the most efficient method. Note that if the application is going to idle for a long period of time, the connection should be closed so the QuickBooks background process can close.


We appreciate your feedback. If you have any questions, comments, or suggestions about this entry please contact our support team at support@4dpayments.com.