The leader in industrial automation and control solutions

Overview & Concepts

SQL Database Integration in EasyBuilder Pro allows an HMI to store and retrieve data from an external SQL database. By connecting to a database server over the network, the HMI can write operational data such as process values, production counts, or event records directly to a structured database table. This enables long-term storage and analysis of system data outside of the HMI device.

To use SQL integration, the HMI must be configured with the database server connection details and the table structure where the data will be stored. The HMI then sends data entries to the database as records according to the configured logging or data transfer settings.

Typical database integration tasks include:

  • Writing process data or production results to database tables
  • Storing historical records for reporting or analysis
  • Allowing external systems to access HMI-collected data

By using a SQL database, data collected by the HMI can be stored centrally and accessed by other software systems such as reporting tools, analytics platforms, or enterprise applications. This allows machine or process data to be integrated into broader monitoring and data management systems.

EBPro Database Server Object menu icon

Implementation: Database Server Object

EasyBuilder Pro offers a Database Server Object, which enables connection with a MySQL or MS SQL database server. This allows users to send data or event log information from the HMI to the database, or to use SQL Queries to access data from the database. Prior to creating or viewing an SQL Query Object, the Database Server Object must first be created and configured.

Configuration

Click the Database Server icon on the toolbar to create a Database Server object. Or, click [Data/History] » [Database Server] in the menu.

Database Server Object.  This object is in the Data/History ribbon toolbar in the main EBPro workspace.

General Tab

EBPro Database Server Object, general tab. This is where the server is chosen as well as the server connection parameters are configured
SettingDescription
Server systemSupported server systems: MySQL, MS SQL Server
IPEnter the IP address of the database.
Use domain nameSupports designating a server using a domain name.
Use server nameThis option is only available when the selected server system is MS SQL Server. An instance stands for a communication port number, and the port number can be used to identify multiple database servers on the same computer.

A server name can be in one of the following formats.
• <Computer name><Instance name>
• <Computer name> (Connect to Default Instance : MSSQLSERVER)
• <IP address><Instance name>
• <IP address> (Connect to Default Instance : MSSQLSERVER)
PortEnter the port number of the database.
UsernameEnter the username for connecting the database. The maximum is 32 words.
PasswordEnter the password for connecting the database. The maximum is 32 words.
Database nameEnter the name of the database for collecting historical data.
Customize timeoutTimeouts for the following operations can be customized.

Connect timeout
The timeout for connection attempts. Connection attempts will be terminated when the timeout is reached.
Read timeout
The timeout for read operations.
Write timeout
The timeout for write operations.

TLS/SSL Tab

EBPro Database Server Object, TLS/SSL Tab. This is where encryption and certificates are configured.
SettingDescription
EnableEnable TLS/SSL security.
TLS version can be selected from: TLS 1.0, TLS 1.1, and TLS 1.2.
Server verificationEnable
Verify whether the server certificate is signed by CA (certificate authority) certificate. Server certificate is sent from server during connection.

Server name must match certificate’s information
Verify whether the server’s domain name or IP matches the records in the server certificate. Domain name and IP records are stored in Subject Alternative Name of the certificate.

Status/Control Tab

Database Server Object, Status/Control tab. This tab is where the status and control addresses (control address is optional) are defined.
SettingDescription
Status addressLW-n: Displays the connection status of Database Server.
Value – Description
0 – Not attempting to connect to database.
1 – Failed to connect to database.
2 – Connection succeeded.

LW-n+1: Error indicator.
Value – Description
0 – No error.
1 – Unknown error.
2 – Failed to connect to database.
3 – Database blocks the unauthorized connection.
4 – Incorrect database name.
5 – Invalid domain name.
6 – Exceeded connection limit.
Control addressLW-n: Controls the operation of Database Server.
Value – Description
0 – Ready
1 – Start
2 – Stop
3 – Update

LW-n+1: Sets the IP address of the database.
LW-n+5: Sets the port number of the database.
LW-n+6: Sets the username for connecting database.
LW-n+22: Sets the password for connecting database.
LW-n+38: Sets the name of the database for collecting historical data.

Notes:

  • If sampled data is successfully synchronized to the SQL database, three tables will be generated in the database, and the sampled data is saved in *_data table.
TableDescription
<HMI NAME> <DATALOG NAME>_dataSaves data sampling
<HMI NAME> <DATALOG NAME>_data_formatSystem folder
<HMI NAME> <DATALOG NAME>_data_sectionSystem folder
  • When synchronizing event log, the three tables generated in the database are listed as the following table, and the event log is saved in *_event table.
TableDescription
<HMI NAME>_eventSaves event log
<HMI NAME>_event_logSystem folder
<HMI NAME>_event_update_timeSystem folder
  • If the content of data sampling / event log, such as data format or event message, is changed and downloaded to HMI, please delete the tables listed above first, and then the new content will thus be effective.
  • Azure SQL Server is supported. To use Azure SQL Server, select MS SQL as server system and use domain name. Azure SQL Server has firewall settings, please add the client into whitelist, and see how to configure by opening the link below:

https://learn.microsoft.com/en-us/azure/azure-sql/database/single-database-manage?view=azuresql#manage-an-existing-server

Example

Create a Database Server object, set Status Address to LW-0, and Control Address to LW-10.

In this example we are creating a database server object, and using the control address of LW-10, with LW-0 being the status address.

Create a Data Sampling object, in [Sync. to database] group box select [Enable], and set Control Address to LW-80, to update or clear HMI historical data. For information on creating a Data Sampling Object, visit the Data Sampling / Data Logging & Trending page.

Creating a Data Sampling object that has the 'sync to database' option enabled.  The database object is selected in the drop-down menu.

If the database is successfully connected, the status indicator LW-0 displays 2 (connection succeeded), and the error indicator LW-10 displays 0 (no error).

Write 2 in LW-80 (sync. data). Open SQL database, the data can be found in table <HMI NAME>_<DATALOG NAME>_data.

Screenshot of the Database itself, showing the data sampling object sending data records.
EBPro SQL Query Menu icon

Implementation: SQL Query

SQL Query can exchange data with SQL database. Before enabling SQL Query, please configure Database Server.

General Tab

SQL Query Object, General tab.  To crate an SQL Query Object, a Database Server Object must first be configured.
SettingDescription
Advanced ModeWithout [Advanced Mode] selected:
Click [New] to add a new row or click [Import from server] to import an existing database.

With [Advanced Mode] selected:
Manually enter syntax in Command tab to control MySQL/MS SQL database.

Please note that returning from Advanced Mode to General Mode is not possible.
DescriptionUser’s description about this query.
DatabaseSelect the source database to read from.
Local: The source database is the SQLite database stored in a USB disk or SD card attached to HMI.
Remote: The source database is the designated Database Server.
File pathUse [Static] or [Dynamic] directory for a local database. When [Static] is selected, please enter the directory in this dialog box. When [Dynamic] is selected, please designate an address as the data source for the file path.
Table nameEnter the name of this query table.
SchemaThe data read from database will be filled into the corresponding address specified in the schema. Please manually set Address Format after reading data.

Notes:

  • A Primary Key should contain only numeric values.
  • In MySQL, Auto Increment must be enabled for Primary Key.
Screenshot of MySQL database with the "Auto Increment" option enabled.  For Primary Key (which should only contain numeric values), the Auto Increment must be enabled.

Command Tab

SQL Query Object, Command tab.  This tab is where you configure the control addresses (five consecutive registers) to execute commands and show results.  Advanced mode in the General tab is NOT selected
SettingDescription
Control addressDesignate five consecutive registers to execute SQL commands and show results. Of the results, the length of error message can be customized.
CommandIn standard mode (without checking Advanced mode box in General tab), the four basic commands of SQL (Create, Read, Update, and Delete) and their command ID are shown.

Advanced Mode

In the Command table in Advanced Mode, [No. of arguments], [No. of outputs], and [Action] columns can be found. Outputting multiple results to consecutive addresses at a time is possible.

SQL Query Object, Command tab. This tab is where you configure the control addresses (five consecutive registers) to execute commands and show results. Advanced mode in the General tab IS selected, giving more config options
SettingDescription
Control addressSpecify the ID number used to give this command.
Row selectionSpecify a row.
StatusDisplays the execution status.
Error codeDisplays the execution result.
Error messageDisplays the error message sent from database server. The default length of the error message is 64 words. Customizing the length of the error message is also possible, and the upper limit is 200 words.
No. of resultsDisplays the number of output results.
New / Delete / Settings / CopyAdd, delete, set, or copy a SQL Query command.

Query Tab

SQL Query Command dialog, Query tab. This dialog pops up when selecting &#039;New&#039; in the Advanced Mode Command tab
SettingDescription
Command IDSpecify the ID number used to give this command.
DescriptionEnter the description of this command.
SQL QueryEnter the syntax for this command.
An argument should be enclosed in braces: ${argument no.}
Discard resultWith this checkbox selected, the result of executing this command will not be shown in SQL Query Result Viewer object. This checkbox can be selected for commands that are done directly to the database without the need for returning a result, such as INSERT INTO, UPDATE, DELETE…etc.

Argument Tab

If argument is used in the syntax of a command in [Query] tab, the system will refer to the address specified in this tab according to the argument number enclosed in ${argument no.}.

SQL Query Command dialog, Argument tab.  This dialog pops up when selecting 'New' in the  Advanced Mode Command tab.

Output Tab

When performing a database query in Advanced Mode, the query results will be sequentially stored at the addresses specified on the [Output] settings page. If the [Multiple results] option is selected, the system will output the query results in bulk to a series of consecutive addresses.

[Multiple Results] Not Selected

Output tab with [multiple results] not selected: query results will be sequentially stored at the specified addresses.

[Multiple Results] Selected

Output tab with [multiple results] selected: the query results will be output in bulk to a series of consecutive addresses.

SettingDescription
Bulk addressThe starting output address for the database query results.
Maximum number of resultsThe [Maximum number of results] can limit the number of outputs from the database query, with an upper limit of 1000 results. The fields included in each query result, and their address format and word length need to be specified.

Note that [Maximum number of results] x [No. of outputs] cannot exceed 10000, meaning a maximum of 10000 addresses can be used for output.

For example, if the maximum number of results is set to 100, and the query returns 300 results:
When [Row selection] is set to 20, the 20th~119th results will be output to the bulk addresses.
When [Row selection] is set to 260, the 260th~299th results will be output to the bulk addresses.
Show the addresses of the Nth resultsShows the output address of the Nth result in the Address column of the table below this setting.
If the address of the output of the first result is LW-200 and the number of words in a result is OFFSET, the address of the output of the Nth result is LW-200+OFFSET*N.

Status

ValueMeaning
0Normal
1Query result exceeds 1000 records. Using LIMIT clause can constrain the number of rows in one page.

Error Code

Error CodeMeaning
0No mistakes
1Unknown error
2Invalid command
3Database Server is not connected yet
4Argument cannot be read
5Cannot write and output
6Incorrect number of arguments
7Error in MySQL, please read error message
8Unsupported datatype
9Number of columns exceeds the limit
10Number of rows exceeds the limit
11Unable to read local database directory
12Name of local database does not exist
13Internal error

Converting Datatype

Converting datatype as shown in the following table will take place after reading MySQL database. If conversion cannot run properly, error code 5 will show. For example, when converting MySQL’s INT into EasyBuilder Pro’s 16-bit Unsigned, if the value exceeds the limit of 16-bit Unsigned, error code 5 will show.

MySQL Data FormatEasyBuilder Pro Datatype
TINYINT16/32-bit BCD
SMALLINT16/32-bit HEX
MEDIUMINT16/32-bit Binary
INT16/32-bit Signed
BIGINT, BIT16/32-bit Unsigned
FLOAT, DOUBLE, DECIMAL32-bit Float
DATETIME, CHAR, BINARY, VARCHAR, VARBINARY, TINYBLOB, TINYTEXT, BLOB, TEXT, MEDIUMBLOB, MEDIUMTEXT, LONGBLOB, LONGTEXTString
EBPro SQL Query Result Viewer Object Menu icon

Implementation: SQL Query Result Viewer

This object shows the results obtained by running the SQL Query operation.

Click on [Data/History] » [SQL Query Result Viewer] to open the settings dialog box. Configure the parameters and click OK; a SQL Query Result Viewer will be created.

General Tab

SQL Query Result Viewer Object.  This object shows the results that are obtained by running the SQL Query operation.  Simply configure the parameters and click OK; an SQL Query Result Viewer Object will be created on the active EasyBuilder Pro project window.