Although you will normally not specifically open or close a database, you have commands that allow you to do so. You must first specify a table using either the DB_FILE command or by changing the active table by using the DB_SELECT command with the ACTIVE keyword. The commands to open and close a database are:

$set_var DB_ACTION open_database

$set_var DB_ACTION close_database

Normally, you will use the DB_SELECT command with a selection option to retrieve records from the database. The database will automatically be opened by the selection process. In fact, some sort of record selection process is necessary to create a record set for a table so records may be read and written.

When you just want to append records to a database, you may use the open command to create a record set before appending records. The open command does an intrinsic select of the first record to establish the record set so you may begin appending records. Unless some sort of selection criteria is used to open the table, the default behavior is to select all of the records in the table when it is opened. Using a select command to only select the first record reduces the overhead of just opening a table and prepares it for output. Not all database providers support this operation. So it is possible that the open operation may fail in some cases.

All database resources are closed and freed when the line is reset. So you do not need to specifically close a database resource. However, stored procedures that return parameter results need to have the resource closed before output parameters can be set. In this case you must close the database resource in order to obtain the results. When the database resource for a stored procedure is closed, the software automatically stores the parameter results in the variable name space for the line using the prefix ID specified in the DB_FILE command and the parameter name to name the variable where the resultant parameter values are stored.