Opening and Closing Connections

In the examples so far, the connection to the database was automatically opened by SenseTalk when needed and closed again when it was no longer required. It is also possible to explicitly open and close database connections. This is done using the open database and close database commands.

Here is an example of opening an ODBC database connection:

set myDB to (type:"odbc", DSN:"DataSource1", user:"root", password:"")

open database myDB

-- any database operations

close database myDB

Here is an example of opening an Excel database connection:

set myExcelDB to (type: "excel", file: ResourcePath("MyCustomers.xlsx"))

open database myExcelDB

-- any database operations

close database myExcelDB

Normally a database connection is only kept open as long as a variable that references it is in use. So connections will usually be closed at the end of any handler that creates them, or possibly even sooner. By explicitly opening a connection as shown above, it will be kept open until it is closed, including during calls to other scripts or handlers. This approach might be desirable if it is important to limit the number of individual connections made to the database. It also might be desirable for reasons of efficiency, if establishing a connection to that database is a particularly time-consuming process.


This topic was last updated on January 15, 2020, at 03:27:21 PM.

Eggplant icon | Documentation Home | User Forums | Support | Copyright © 2020 Eggplant