TODBCConnect

(Engine-Level Function)

Description: Forms a connection to an ODBC database. Similar to ODBCConnect except that it runs in its own thread (see "Comments" section for differences)
Returns: Nothing
Usage: Script Only.
Function Groups: Database and Data Source,  ODBC
Threaded: Yes
Related to: ODBC | ODBCConfigureData | ODBCConnect | ODBCDisconnect | ODBCSources | ODBCStatus | ODBCTables | TODBC | TODBCDisconnect
Format: TODBCConnect(DSName, UserName, Password, DB, ErrorMsg, SQLState, ErrorCode [, Disconnect, LoginTimeout, ConnectionTimeout])
Parameters:  
DSName
Required. Any text expression for the ODBC data source name, as configured in the ODBC setup menu under Microsoft Windows™.
UserName
Required. Any text expression for the ODBC login user name.
Password
Required. Any text expression for the ODBC login password.
DB
Required. An ODBC value for the ODBC database after a connection has been established.
ErrorMsg
Required. Any variable that will contain the last error message returned by the function. If no errors occurred this parameter will be set to 0 to indicate the termination of the thread.
SQLState
Required. Any variable that will contain the SQL state that the statement was in when the last error occurred.
ErrorCode
Required. Any variable that will contain the native error code for the given driver and an error condition for the last error that occurred.
Disconnect
An optional parameter which is any logical expression that determines how errors are to be handled. If true (non-0), the connection to the database will be disconnected should any error (no matter how minor) occur; if false (0) an error will not cause a disconnect to occur. The default value is false.
LoginTimeout
Sets the period (in seconds) which the driver will wait for a login request to complete. The default value of "0" indicates that there is no timeout.
ConnectionTimeout
Sets the period (in seconds) which the driver will wait for any request other than a query or login on the connection to complete. The default value of "0" indicates that there is no timeout.
Comments: When TODBCConnect is executed in its script, it starts its own thread and VTScada will continue executing. This is similar to ODBCConnect except that execution of the application is not suspended while waiting for the connection to the database (i.e. waiting for the return value to be set). Instead, execution continues and sometime in the future when the connection to the database is established, DB will be set to the ODBC value for the database. If any errors occurred, the error parameters, ErrorMsg, SQLState and ErrorCode, would be set at that time to indicate the nature of the error. ErrorCode will be set to zero if no error occurs.
64-bit VTScada. 64-bit VTScada is able to connect to either 64-bit or 32-bit ODBC data sources. ODBCConnect will first try to connect to the database through a 64-bit ODBC driver. If this fails for any reason it will then try the connection through a 32-bit ODBC driver. This means that any ODBC code that worked under 32-bit VTScada should not need to be modified for use with 64-bit VTScada, but 64-bit VTScada has the extra ability of being able to use 64-bit ODBC drivers.

Example:

Init[
  If 1 Wait;
  [
    TODBCConnect("VTS_data" { Driver name },
                 " "," " { No user name or password },
                 ODBCHandle { Handle to use },
                 ErrMsg, ErrState, ErrCode { Error details });
  ]
]
Wait[
  If TimeOut(1, Retry) Init { Retry ODBC every Retry seconds };
  If Valid(ODBCHandle) Main { If valid connection go to Main };
]