Beckhoff TwinCAT
For Beckhoff TwinCAT, SQL4automation provides libraries and sample projects for both TwinCAT V2 (SQL4TwinCAT) and TwinCAT V3 (SQL4TwinCAT3), including a TLS/SSL-capable Version 5 library for TwinCAT V3. Both variants support unencrypted and encrypted communication.
Connecting Beckhoff TwinCAT PLC to SQL Databases, MES, ERP
For Beckhoff TwinCAT V2 and V3, SQL4automation provides dedicated libraries. SQL4TwinCAT (V2) uses the TcpIp.lib socket functions. SQL4TwinCAT3 (V3) uses Tc2_TcpIp.lib, Tc2_Standard, and Tc2_System. Both can run on Soft-PLC or hardware PLC. The TCP/IP server license (TF6310) is required for TwinCAT V3 and is subject to Beckhoff licensing; a 7-day trial license can be activated repeatedly under System License.
Integration of the SQL4TwinCAT Library
The SQL4TwinCAT (V2) and SQL4TwinCAT3 (V3) function blocks receive the Connector IP address, port, and SQL string as parameters. Return values are written to the saTableValues array. Both libraries follow the same step-sequence handshake pattern: xExecute triggers the query, xDone signals completion, xError signals failure. The xHoldConnection parameter keeps the socket open between requests for higher-throughput applications.

SQL4automation Link Settings
The SQL4automation Connector is operated with the target setting "Standard" for TwinCAT V2 and V3 controllers (or "UTF-16" for the V3 UTF-16 variant). The configuration is completed in just a few clicks. Detailed integration instructions are available in the download section.

FAQ’s
Frequently Asked Questions to Beckhoff TwinCAT
Does SQL4automation support both TwinCAT V2 and TwinCAT V3?
Yes. Separate libraries are available for TwinCAT V2 (SQL4TwinCAT using TcpIp.lib) and TwinCAT V3 (SQL4TwinCAT3 using Tc2_TcpIp.lib). Both can run on Soft-PLC or hardware PLC and follow the same integration pattern. A Version 5 library for TwinCAT V3 additionally supports TLS/SSL encrypted communication.
Do I need a separate Beckhoff license to use SQL4automation with TwinCAT?
Yes. The TwinCAT TCP/IP Server is required for both V2 (licensed or 30-day demo) and V3. For TwinCAT V3, the TF6310 - TC3 TCP/IP license must be ordered from Beckhoff. For the Soft-PLC, the TC1200 - TC3 PLC license is also required. Both support repeated 7-day trial activations under System License.
What is the difference between the Standard and UTF-16 variants for TwinCAT V3?
Both variants are functionally identical. The Standard variant uses the default string encoding; the UTF-16 variant uses UTF-16 encoded strings in the SQL telegram. Select the variant that matches your database or middleware configuration. Both support unencrypted and TLS/SSL encrypted connections.
Can SQL4automation connect a Beckhoff TwinCAT PLC to any SQL database?
Yes. SQL4automation supports all ODBC-compatible databases including Microsoft SQL Server, MySQL, MariaDB, PostgreSQL, Oracle, and SQLite. The database is configured in the SQL4automation Connector on the Windows PC. No changes to the TwinCAT project are required when switching databases.
Does SQL4automation support TLS/SSL encryption for TwinCAT?
Yes, for TwinCAT V3 using the Version 5 library and Connector V5.1.0.0 or newer. Enable encryption by setting xTlsEnable = TRUE and providing the certificate common name, use case, and TLS version (1.3). Certificates are installed via the TwinCAT Security Screen. Always test without encryption first before enabling TLS.
Which Beckhoff TwinCAT systems has SQL4automation been tested on?
SQL4automation has been tested and verified on Beckhoff TwinCAT V2 running on both Soft-PLC ("TwinCAT PLC") and hardware PLC, and on Beckhoff TwinCAT V3 running on both Soft-PLC (TC1200 license) and hardware PLC. Both versions require a Beckhoff TCP/IP Server license (30-day demo available for V2; TF6310 license for V3 with repeatable 7-day trials).
Technical Data
Switch to SQL4automation Now.
Connect industrial controllers directly with SQL databases. Field-proven since 2007 for maximum performance and security, completely without middleware.