Applies To:
  • CitectSCADA 3.x, 4.x

Summary:
What options are available to me if I want to log alarms and reports to my SQL database? What if I also want to read data from my database back into Citect? 

Solution:
Basically there are three ways to exchange data to an external SQL database such as MS Access or Oracle.

Method 1.
he first, is to set up an SQL device from within Citect and let Citect write data to it by report logs, alarm logs, etc. This requires no User Cicode. (there is no way to get data from a device without using Method 2 or 3).

The format and locations of each of your SQL databases are defined through Citects Devices records. This will specify: the format of the database (ie the field names and widths); the Header which is the database connection string for ODBC connection (eg DSN=SybaseDatabase); the database table name etc.

Note 1: All database fields are character(string) field types;

Note 2: The field names defined here must be identical to the field names defined in the referenced SQL database table.

Note 3: It is advisable to specify field lengths. (If they aren't identical you may loose data)

Note 4: If logging Alarms directly to an SQL device, you cannot log the Alarm "Desc" field.  If you do, the SQL INSERT statement generated by Citect will contain the word "Desc" (a reserved SQL word meaning "Descending") which will result in a syntactical error.

Method 2.
The second, is to set up an SQL device from within Citect and use the Cicode Device functions to find data and/or write data to it. Same setup as Method 1 and can be used in conjunction with method 1. (eg : Write data via method 1 & read data via method 2).

To use an SQL device in Citect, you can only use a subset of the Cicode Device functions- namely: DevControl(), DevOpen(), DevClose(), DevFind() DevGetField() and DevWrite(). So you cannot actually modify the device definition in runtime. To write Citect data to an SQL database, you can use the DevWrite() function (DevWrite automatically adds a new record - you can't modify an existing record) to write to all fields in the new record. No data is written to the database if you do not write to all fields. To delete records from an SQL database you must use the Cicode SQL functions described below.

Method 3.
Rather than accessing the database as a device you can use the Cicode SQL functions for direct control over SQL transactions. This method provides FAR grater flexibility and is FAR more powerful. See the SQLConnect() function in the Citect Help for examples.

Notes:

  1. ALL methods require an ODBC database driver to be installed. Setup the driver through the windows control panel - ODBC icon, and enter the Data Source Name (DSN).
  2. Method 1 & 2 requires an SQL device to be configured within Citect.
  3. You CAN communicate via a combination of all the above methods.
  4. Unlike a dBASE file you must create the SQL database by an external application before it can be used.
  5. If logging alarms directly to an SQL device - the device must have field names identical to those defined in Citect's alarm summary or alarm log format. ie the whole format should be identical. Currently Citect will not use the alarm format as a default hence the need to duplicate it in the SQL device format section. So, the field names must be identical in 3 locations: the alarm format, the SQL device format and the SQL database table field names.
  6. If you are wanting to send alarm logs and simple reports to an SQL database, it is easiest to use method 1.
  7. Refer to On-line help or the Users Guide - "Exchanging Data with Other Applications" and "Using Devices" chapters for further information.

Related Articles Q2034

 

Keywords:
 

Attachments