How to Log to a Database on the NJ Series
How Database Logging Works
Structure data is temporarily stored in the ring buffer
When inserting into the database, data is read from the ring buffer and the DB_Insert instruction is executed

Why use a ring buffer
Response times for database communication vary with network conditions and server load. Therefore a ring buffer is used to separate collection processing from DB write processing.
Benefits of saving to a database
- Long-term history management
- Easy searching and aggregation
- Centralized management of data from multiple machines
- Easy integration with MES and BI tools
Function blocks used
Uses the ring buffer functions


Structure for logging

Ladder program example

Connects to the DB (DB_Connect) 3 seconds after power ON
If there are records in the ring buffer, one record is taken from the ring buffer and added to the DB (DB_Insert)
FAQ
Which databases can it connect to?
ODBC databases supported by the NJ series can be used.
Can DB_Insert be executed every scan?
It increases communication load, so processing via a ring buffer is recommended.
How does it differ from saving to an SD card?
Saving to a database makes searching and aggregation easy, but requires a network and a server.
What happens if the database connection is lost?
A common configuration keeps data in the ring buffer and saves it after reconnecting.
