CODESYS

For CODESYS, SQL4automation provides two sample projects: one for CODESYS V2 and one for CODESYS V3 controllers. SQL4CODESYS can be directly integrated as a library and runs on all CODESYS controllers that support SysSocket.lib (V3) or SysLibSockets.lib (V2) and are equipped with an Ethernet interface.

Connecting CODESYS PLC to SQL Databases, MES, ERP

For CODESYS, SQL4automation provides two sample projects: one for CODESYS V2 and one for CODESYS V3 controllers. SQL4CODESYS can be directly integrated as a library. It runs on all CODESYS controllers that support SysSocket.lib (V3) or SysLibSockets.lib (V2) and are equipped with an Ethernet interface, covering a wide ecosystem of controllers from Wago, Bosch Rexroth, Festo, KEBA, and many others.

Integration of the SQL4CODESYS Library

The SQL4CODESYS library receives parameters such as the IP address and port of the Connector as well as the SQL string. The return values of the SQL query are written to the two-dimensional string array ptTableValues (V2) or returned via the stResult structure (V3). The library is imported directly into the CODESYS project and requires no modifications to the runtime or operating system.

SQL4automation Link Settings

The SQL4automation Connector is operated with the target setting "Standard" for CODESYS controllers. The configuration is completed in just a few clicks. Detailed integration instructions are available in the download section.

FAQ's

Freuqently Asked Questions to CODESYS

Which CODESYS runtime versions does SQL4automation support?

SQL4automation supports both CODESYS V2 and CODESYS V3. For V3, the controller must support SysSocket.lib and run CODESYS 3.5.11.0 or newer, along with the required standard libraries (Memory, Network, Standard, SysMem, SysTypes2 Interfaces). For V2, SysLibSockets.lib is required. Both versions include sample projects and require an Ethernet interface on the controller.

Can SQL4automation connect a Wago PLC to a SQL database?

Yes. SQL4automation has been tested and verified on Wago 750-885, 750-841, I/O-IPC, Speedway, and PFC100/200 series controllers. All run CODESYS and support the required socket library. The SQL4CODESYS library integrates directly into the Wago project without any additional runtime components.

Does SQL4automation work with CODESYS-based controllers from third-party manufacturers?

Yes. SQL4automation is compatible with any CODESYS-based controller that supports the standard CODESYS socket libraries and has an Ethernet interface. This covers Bosch Rexroth, Wago, Festo, KEBA, Solvimus, Kendrion Kuhnke, and many more. If your controller is not listed, contact us for compatibility verification.

How are SQL query results returned to the CODESYS program?

In CODESYS V2, results are written to the global two-dimensional string array saTableValues (rows x columns). In CODESYS V3, results are accessed via the stResult structure and the GetData() / GetColumnName() methods. Row and column indices are 0-based. No parsing, no serialisation, and no custom protocol implementation is required.

Does SQL4automation support TLS encrypted communication for CODESYS?

Yes, for CODESYS V3 using the Version 5 library and Connector V5.1.0.0 or newer. Encryption is enabled by setting xTlsEnable = TRUE and providing the certificate common name, use case, and TLS version (1.3). Certificates are installed via the CODESYS Security Screen. Always commission and test the connection without encryption first.

With which CODESYS PLCs has the SQL4CODESYS library been tested successfully?

CODESYS SP PLC WinNT, CODESYS SP RTE, CODESYS Control Win SL, CODESYS Control RTE SL, Bosch Rexroth L20, Bosch,,, Rexroth L25, Wago 750-885, Wago 750-841, Wago I/O-IPC, Wago Speedway, Wago PFC100/200, KEBA CP-242, Solvimus auvis.box, Festo CPX, Festo CEC, Kendrion Kuhnke FIO Controller 113

Technical Data

REQUIREMENTS & VERSION INFO
CODESYS V2 minimum CoDeSys SysLibSockets.lib must be available and added in the library manager
CODESYS V3 minimum CODESYS 3.5.11.0 or newer
V3 required libraries Memory V3.5.7.0, Network V3.5.7.0, Standard V3.5.9.0, SysMem 3.5.5.0, SysTypes2 Interfaces 3.5.4.0
TLS support TLS/SSL encrypted communication available from CODESYS V3 (Version 5 library) + Connector V5.1.0.0 or newer
TLS library file S4A_SQL4CodesysV3.compiled-library installed via S4A_SQL4CODESYS_Sample.projectarchive
REQUIRED BLOCKS / LIBRARIES
  • SQL4CoDeSys.lib (V2) or S4A_SQL4CodesysV3.compiled-library (V3)
  • SysLibSockets.lib (V2) added in library manager
  • Memory V3.5.7.0 (V3 only)
  • Network V3.5.7.0 (V3 only)
  • Standard V3.5.9.0 (V3 only)
  • SysMem 3.5.5.0 (V3 only)
  • SysTypes2 Interfaces 3.5.4.0 (V3 only)
TLS / SSL ENCRYPTION
Connector version TLS/SSL requires SQL4automation Connector V5.1.0.0 or newer and SQL4CODESYS V3 Version 5 library
Certificate paths C:\ProgramData\SQL4automation\certs\CA (RootCA)
C:\ProgramData\SQL4automation\certs\S4AConnector (server cert)
C:\ProgramData\SQL4automation\certs\S4AQueryTool (query tool cert)
CODESYS TLS params xTlsEnable: TRUE
sTlsCertificateCommonName: <IP address of PLC>
sTlsUseCase: SQL4automation
sTlsVersion: 1.3
Certificate setup In CODESYS programming environment: View > Security Screen > connect to controller. Add client cert under Devices > Own Certificates. Add server cert under Devices > Trusted Certificates.
Commissioning order Always test connection WITHOUT TLS first. Only enable encryption once unencrypted communication is confirmed working. Check system time before enabling TLS.
FUNCTION BLOCK PARAMETERS
Parameter Type Description
xExecute BOOL Triggers the database request
sIPAddress STRING(15) IP address of the SQL4automation Connector
iPort INT Port number of the SQL4automation Connector
tTimeout TIME Communication timeout
xHoldConnection BOOL Keeps the socket connection open after a database query
dwRequestBufferSize DWORD Size of the request data buffer (V3 only)
dwResponseBufferSize DWORD Size of the response data buffer (V3 only)
dwResponseMaxReturnParams DWORD Maximum number of return parameters (Connector >= V4.0, default 0) (V3 only)
dwResponseMaxRows DWORD Maximum number of rows in the response (V3 only)
dwResponseMaxColumns DWORD Maximum number of columns in the response (V3 only)
dwResponseMaxStringLen DWORD Maximum string length in the response (V3 only)
dwResponseCutStringLen DWORD Strings longer than this are truncated (0 = inactive) (V3 only)
xReady BOOL Output: ready for a new database query
xBusy BOOL Output: database query is in progress
xDone BOOL Output: database query completed successfully
xError BOOL Output: database query ended with an error
stResult.diResultState DINT Output: status / error code (0 = no error) (V3)
stResult.dwResultRows DWORD Output: number of rows returned (V3)
stResult.dwResultColumns DWORD Output: number of columns returned (V3)
diResultState DINT Output: status / error code (0 = no error) (V2)
diResultRows DINT Output: number of rows returned (V2)
diResultColumns DINT Output: number of columns returned (V2)
BUFFER & GLOBAL CONSTANTS
Constant Default Description
diMaxRows 50 Max number of datasets from the table array (V2)
diMaxColumns 15 Max number of columns from the table array (V2)
diStringLength 40 String length in the table array (V2)
diMaxReturnParameter 5 Max number of return parameters (V2)
diUBoundRequestArray 20 Upper boundary of the request string array (V2)
diRequestStringLength 80 String length of the request string array (V2)
diReadDataBuffer 4096 Max bytes of read buffer (V2)
diSendDataBuffer 2048 Max bytes of send buffer (V2)
ERROR CODES (diResultState)
Error Code Description
1 Unknown SQL command
2 Query returns more records than diMaxRows. Adjust query or increase diMaxRows.
3 Query returns more columns than diMaxColumns. Adjust query or increase diMaxColumns.
5 Query returns at least one value larger than MaxStringLength. Adjust query or increase MaxStringLength.
10 Internal Connector error
11 Internal Connector error; database cannot be opened
21 No IP address defined (sIPAddress = '')
22 No port number defined (iPort = 0)
23 Request string is empty
24 MaxRows not defined (diMaxRows = 0)
25 MaxColumns not defined (diMaxColumns = 0)
26 Pointer to TableValues array is not defined (V2 only)
27 Pointer to ColumnsName array is not defined (V2 only)
28 Pointer to Request array is not defined (V2 only)
29 MaxStringLength not defined (diStringLength = 0)
30 Pointer to ReturnParameter array is not defined (V2 only)
41 No connection to SQL4automation Connector. Check firewall, IP address, and port.
50 Sending the complete request string failed. Check connection or TCP buffer. (V2 only)
51 Request string is larger than the send buffer (diSendDataBuffer)
71 Connection to SQL4automation Connector cannot be closed (V2 only)
99 Timeout: no response from the Connector within the time window
>100 ODBC database connection error codes
40002 General error in the SQL query; request string is invalid

Switch to SQL4automation Now.

Connect industrial controllers directly with SQL databases. Field-proven since 2007 for maximum performance and security, completely without middleware.

CODESYS
by Industry.