We need to take some time to discuss session management. It would be nice if your AEP did not have to create connections, tables, and queries every time it was called. To help facilitate this sort of functionality, AEP containers can implement two special procedures; Startup and Shutdown. The Startup function will be called by Advantage, on a per-connection basis, the first time a procedure inside of the AEP container is called. The Shutdown function will be called, on a per-connection basis, as each connection that has used the AEP container is closed. This means the Startup function is called once for each Advantage connection that begins using procedures inside of the AEP container, and the Shutdown function is also called once for each Advantage connection that has used procedures inside of the AEP container.
It is important when developing AEPs to keep in mind that they will be run by a multi-threaded server (Advantage). The Advantage Database Server does not necessarily use the same thread every time it executes requests for the client, so thread variables are not a suitable solution for providing client-specific storage in an AEP. All AEP functions are passed a unique identifier, the ulConnectionID parameter. This parameter can be used by the developer to uniquely identify a client connection. Resources allocated on behalf of the client (connections, open tables, etc) can be tied to this unique connection id, and retrieved at a later time.
Keeping this in mind, take some time to familiarize yourself with the Startup and Shutdown functions that were generated for you in the AEP template.
The Startup and Shutdown functions that were automatically generated in the template will be sufficient for this tutorial. Continue on to the next task.