ODBC Manager Service

This service module provides a number of useful database access features to free other application layers from having to do this. Modules executing queries are designed to be called as launched modules (in a script) and will remain active until complete.

ODBC Manager Library Startup

On initial startup, the ODBC Manager library waits until the RPC Manager has started (\RPCManager\Started). If this service fails to start, the ODBC Manager library will be prevented from starting.

After the RPC Manager has started, the ODBC Manager library makes a call to a global system function “\ODBCSetup()”. This is not a VTScada module, but rather one that you may choose to create and declare in your AppRoot.SRC file. (It is not mandatory.) Should you choose to create an ODBCSetup module, it may function as either a subroutine or a launched module. The purpose of this module is to perform any application-specific tasks that must occur before the ODBC Manager library is started.

ODBC Manager Logging

On initial startup, the ODBCManager ensures that a subdirectory named ODBCManager exists below the application's directory. The purpose of this directory is to provide a location for the optional log file, ODBCManager.log.

Logging can enabled with a check box in the ODBC Statistics dialog (ODBC Statistics). If logging is enabled, the log file will be created automatically. The log file can also be created if you attempt to view it via the View Log button in the ODBC Statistics dialog before any logging has actually happened to cause the creation of a log file.

The log file is stored as plain text and can be viewed with any editor.

The Clear Log button causes the .log file to be deleted. You will be prompted to confirm that you want to proceed.

Example Module using the ODBC Manager:

Idle[
  If True(SQLRequest) WaitQuery;
  [
    SQLRequest = FALSE;
    ErrorCode = Invalid;                    { Should be invalid before each ExecuteQuery }
    dbQuery    = "SELECT * FROM MY_TABLE";  { Any valid SQL statement }
    DSNString  = "MyDSN";                   { Name of DSN configured in ODBC Data Sources control panel }
    dbUserName = "MyName";                  { Database username }
    dbPassword = "secret"                   { Associated password }
      { ExecuteQuery will implicilty make a connection to the database if there is not an existing one }
    \ODBCManager\ExecuteQuery(&ErrorCode, dbQuery, DSNString, dbUserName, dbPassword, &Result);)
  ]
]
WaitQuery[
    { Need to wait for ErrorCode to become valid (indicates that query is done)}
  If ErrorCode == 0 HandleGoodData;
  If ErrorCode > 0 HandleError;
]
HandleGoodData[
  If 1 Idle;
  [
    { Process query result in Result }
  ]
]
HandleError[
  If 1 Idle;
  [
    { Handle query error }
  ]
]