You are on page 1of 57

Connection of an

SQL database to an
S7-1500 Software
Controller
Siemens
SIMATIC ODK 1500S-SQL-driver V3.1 Industry
Online
https://support.industry.siemens.com/cs/ww/en/view/109479140 Support
Warranty and liability

Warranty and liability

Note The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any eventuality. The Application
Examples do not represent customer-specific solutions. They are only intended
to provide support for typical applications. You are responsible for ensuring that
the described products are used correctly. These application examples do not
relieve you of the responsibility to use safe practices in application, installation,
operation and maintenance. When using these Application Examples, you
recognize that we cannot be made liable for any damage/claims beyond the
liability clause described. We reserve the right to make changes to these
Application Examples at any time without prior notice.
If there are any deviations between the recommendations provided in these
application examples and other Siemens publications – e.g. Catalogs – the
contents of the other documents have priority.

We do not accept any liability for the information contained in this document.

Any claims against us – based on whatever legal reason – resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this Application Example shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life,
© Siemens AG 2020 All rights reserved

body or health, guarantee for the quality of a product, fraudulent concealment of a


deficiency or breach of a condition which goes to the root of the contract
(“wesentliche Vertragspflichten”). The damages for a breach of a substantial
contractual obligation are, however, limited to the foreseeable damage, typical for
the type of contract, except in the event of intent or gross negligence or injury to
life, body or health. The above provisions do not imply a change of the burden of
proof to your detriment.

Any form of duplication or distribution of these Application Examples or excerpts


hereof is prohibited without the expressed consent of the Siemens AG.

Security Siemens provides products and solutions with industrial security functions that
informa- support the secure operation of plants, solutions, machines, equipment and/or
tion networks. They are important components in a holistic industrial security
concept. With this in mind, Siemens’ products and solutions undergo continuous
development. Siemens recommends strongly that you regularly check for
product updates.
For the secure operation of Siemens products and solutions, it is necessary to
take suitable preventive action (e.g. cell protection concept) and integrate each
component into a holistic, state-of-the-art industrial security concept. Third-party
products that may be in use should also be considered. For more information
about industrial security, visit http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a product-
specific newsletter. For more information, visit
http://support.industry.siemens.com.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 2
Table of contents

Table of contents
Warranty and liability ................................................................................................... 2
1 Introduction ........................................................................................................ 5
2 Task ..................................................................................................................... 6
2.1 Overview............................................................................................... 6
3 Solution............................................................................................................... 7
3.1 Overview............................................................................................... 7
3.2 Description of the core functions .......................................................... 7
3.3 Hardware and software components ................................................... 7
3.3.1 Supported SQL databases ................................................................... 8
3.3.2 Supported SQL datatypes .................................................................... 9
3.3.3 Performance data ............................................................................... 11
3.3.4 Used components .............................................................................. 11
3.4 Versioning and update of the driver ................................................... 12
3.5 New features and changes ODK 1500S SQL driver V3 .................... 14
3.6 License mechanism ............................................................................ 14
4 Function mechanisms ..................................................................................... 16
4.1 Overview of the functional principle ................................................... 16
4.1.1 Write process data ............................................................................. 16
4.1.2 Universal SQL interface ..................................................................... 17
© Siemens AG 2020 All rights reserved

4.2 Overview function blocks.................................................................... 17


4.3 Description of the function blocks ...................................................... 19
4.3.1 ODK1500S_SQL_V3_Load ............................................................... 19
4.3.2 ODK1500S_SQL_V3_Execute .......................................................... 19
4.3.3 ODK1500S_SQL_V3_ExecuteSimple ............................................... 22
4.3.4 ODK1500S_SQL_V3_InsertUpdate ................................................... 23
4.3.5 ODK1500S_SQL_V3_Unload ............................................................ 25
4.4 Create configuration data block ......................................................... 26
4.4.1 Example data block ............................................................................ 27
4.4.2 Create configuration data block with the ConfigDBCreator ............... 29
4.4.3 Restriction ODK1500S ConfigDBCreator ........................................... 33
5 Installation and commissioning ..................................................................... 34
5.1 Installation and commissioning of the MSSQL demo database......... 34
5.1.1 Installation MSSQL Server 2014 Express and Tools ......................... 34
5.1.2 Configuration of the SQL server ......................................................... 37
5.1.3 Generation of the sample database by a script ................................. 38
5.2 Installation and commissioning of the SQL driver on the runtime
PC....................................................................................................... 40
5.2.1 Installation of the SQL driver DLL ...................................................... 40
5.2.2 Configuration of the ODBC driver ...................................................... 40
6 Operation of the application ........................................................................... 42
6.1 Use of the example application .......................................................... 42
6.1.1 Structure of the STEP 7 example project ........................................... 43
6.1.2 Loading of SQL driver DLL ................................................................. 45
6.1.3 Execution of SQL statements ............................................................. 46
6.1.4 Write process data ............................................................................. 46
6.1.5 Unload SQL driver DLL ...................................................................... 46
6.1.6 Error analysis ..................................................................................... 47
6.2 Adaption of the example application to own requirements ................ 47
6.2.1 Adaption of the connection information .............................................. 47
6.2.2 Adaption of the SQL statements ........................................................ 47

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 3
Table of contents

7 Status and Error codes ................................................................................... 49


7.1 Status and Error Codes ODK1500S .................................................. 49
7.2 Error Codes ODK1500S SQL driver .................................................. 52
7.2.1 Function Error Codes ......................................................................... 52
7.2.2 SQL Error Info .................................................................................... 52
8 Output and display of log information .......................................................... 53
9 Related literature ............................................................................................. 55
10 Contact partner ................................................................................................ 56
11 History............................................................................................................... 57
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 4
1 Introduction

1 Introduction
This document describes the connection of an S7-1500 Software Controller to an
SQL-database with ODK 1500S-SQL-driver.
Among others, you will find a description of how to send SQL-statements to an
SQL database and how to request data from an SQL database by means of the
driver or write data in a database from a data block.
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 5
2 Task
2.1 Overview

2 Task
2.1 Overview
Introduction
In the field of the automation technology, there is a great number of applications for
a database.
Databases permit a central, fast, structured and reliable data storage.
Programmable logic controllers, such as S7-1500 controllers, are used for the
control of machines and production plants but, however, are hardly suitable to store
large amounts of data that occur or are required during the production.
Thus, a connection of a database to a programmable logic controller offers a lot of
advantages and use cases.
For example, you can use databases to log machine data or messages during the
production. In this case, the controller transmits data to the database.
Another use case is that the controller reads out parameters, which are required to
produce a certain product series, from a central database.

Overview of the automation task


The following figure gives an overview of a possible automation task.
© Siemens AG 2020 All rights reserved

Figure 2-1: Example automation task

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 6
3 Solution
3.1 Overview

3 Solution
3.1 Overview
It is not possible to connect a database to an S7-1500 controller by default.
To solve this problem, an SQL driver for the S7-1500 Software Controller has been
developed with the ODK 1500S (Open Development Kit). You can use the SQL
driver to transmit data from an S7-1500 Software Controller to an SQL database or
to read out data from an SQL database.
The connection to the database (local or remote) is established via the ODBC-
interface (open database connectivity).
The ODK 1500S-SQL driver consists of function blocks for the S7-user program as
well as of a Windows-DLL.

Required knowledge
Basic knowledge concerning SQL databases, SQL statements and TIA portal is
assumed.

3.2 Description of the core functions


The following SQL database functions are supported by means of the driver:
© Siemens AG 2020 All rights reserved

• Transmission of SQL statements with flexible arguments.


for example:
– SELECT
– INSERT
– UPDATE
– DELETE
• Read data from SQL-database (via SELECT)
• Write data from data block into SQL database

Note The four mentioned SQL statements have been tested. In addition to these
statements, all other SQL statements can be empirically used, too (e.g. execute
statements for stored procedures), as the SQL driver transmits the SQL strings
and SQL arguments, which have been transferred by the user, directly to the
SQL database via the ODBC interface.
Due to the variety of the SQL statements as well as the possible combinations
not all variations can be tested. The use of SQL statements other than
mentioned above can be done on own responsibility.

3.3 Hardware and software components


Reference system: The application was developed and tested in a laboratory
environment with the following components. The customer is responsible for the
usage in a productive system. Customer specific adjustments are to be clarified
individually.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 7
3 Solution
3.3 Hardware and software components

3.3.1 Supported SQL databases

The ODK1500S SQL driver has been tested with the following databases:
• Microsoft SQL 2014 Server Express
• MySQL Server 5.7
• Oracle Database 11g Express Edition
• MariaDB 10.3
• PostgreSQL 12
Empirically any database which offers an ODBC interface can be used with the
ODK1500S SQL driver. The usage of the ODK1500S SQL driver with databases
other than stated above can be done on own responsibility. There may be
restrictions especially for certain data types.
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 8
© Siemens AG 2020 All rights reserved

3 Solution
3.3 Hardware and software components

3.3.2 Supported SQL datatypes

The SIMATIC ODK 1500S SQL driver supports the following SQL datatypes:

Table 3-1: Supported SQL datatypes


MS SQL datatype My SQL datatype Oracle SQL PostgreSQL STEP 7 datatype
datatype datatype
varchar(n) varchar2(n) String[n]
nvarchar(n) varchar(n) nvarchar2 character WString[n]
enum WString
bigint bigint(20) bigint LInt
int int(11) number(10,0) integer DInt
smallint smallint(6) number(5,0) smallint Int
tinyint tinyint(4) number(3,0) Sint
float, double double binary_double double precision LReal
real float binary_float real Real
bit bit(1) number(1,0) bit**** Bool
datetime(6) timestamp* timestamp without
datetime2(6) DTL
timezone
datetime** datetime(3)** DTL
binary(n)*** binary(n)*** Array[1..n] of Byte
varbinary(n)*** varbinary(n)*** Array[1..n] of Byte
tinyblob*** Array[1..255] of Byte
blob*** Array[1..65535] of
Byte
mediumblob*** Array[1..65535] of
Byte
longblob Array[1..65535] of
Byte

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 9
© Siemens AG 2020 All rights reserved

3 Solution
3.3 Hardware and software components

* Oracle: the time format has to be adapted to the ODBC standard e.g. via login trigger in database for current session:
NLS_DATE_FORMAT:YYYY-MM-DD; NLS_TIMESTAMP_FORMAT: YYYY-MM-DD HH24:MI:SS.FF
** The input parameter "EnableDatimeSupport" at the function block ODK1500_SQLV3_ExecuteStatement or
ODK1500_SQLV3_InsertUpdate has to be enabled
*** read only
**** write only

NOTICE string length


The maximum supported string length n is 254 characters.
Variable string length in read direction is only supported for Microsoft sql
database. In write direction variable string length is supported by all databases.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 10
3 Solution
3.3 Hardware and software components

3.3.3 Performance data

• Up to 1025 data points (variables) resp. 128kByte data can be written to


the database or read from the data base per function call
• The SQL driver FBs are multi instance capable. This means that several
SQL commands can be executed in parallel or, for example, data can be
written to several databases in parallel.
• SQL-statements with up to 16382 characters in STEP 7-program
• The execution time of the SQL function blocks is depending on the
processor performance of the used IPCs
• Average execution time to write 1000 real values (4 kByte) from a data
block into a database takes approximately 40 ms measured with CPU
1505SP FW 2.7 (Open Controller) and SQL Express 2014 Database on
IPC227E

3.3.4 Used components

This application has been developed and tested with the following components:

Hardware components
Table 3-2
© Siemens AG 2020 All rights reserved

Component No. Order number Note


CPU 1515SP PC 1 6ES7 677-2DBx2-0xB0 ET 200SP Open Controller G2
IPC 227E 1 6ES7 647-8BB64-4BA1 Nanobox

Software components

The minimum required software for ODK1500S SQL driver V3 is:


• S7-1500 Software Controller FW 2.5 (Runtime System)
• STEP7 Professional V15 (Engineering)

Newer versions than the above stated (e.g. TIA V16) can be used without any
restriction.

The ODK1500S SQL driver V3 has been developed and tested using the following
software components:
Table 3-3:
Component No. Order number Note
STEP 7 1
Professional V15
SP1
Microsoft SQL 2014 1 64 Bit - Version
Server Express
Edition
Microsoft ODBC 1 64 Bit - Version
Driver 17 for SQL
Server
MySQL Server 5.7 1 64 Bit - Version

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 11
3 Solution
3.4 Versioning and update of the driver

Component No. Order number Note


MySQL 1 64 Bit – Version
Connector/ODBC MySQL ODBC 5.8
5.8 Unicode Driver
Oracle Database 1 https://www.oracle.co
19c Client m/database/technologi
es/oracle19c-
windows-
downloads.html
(WINDOWS.X64_193
000_client.zip)
CPU 1515SP PC 1 6ES7 677-2DBx2-0xB0 Open Controller Gen. 2
FW 2.7 (Windows 10)
CPU 1507S FW 2.7 1 6ES7 672-7AC01-0YA0 Installed on IPC 227E
(Windows 7)
SQL-driver-DLL 1 Windows-DLL
V3.0

Sample files and projects


The following list includes all files and projects being used in this application
example.
Table 3-4
© Siemens AG 2020 All rights reserved

Component Note
ODK1500S-SQL-V3_1_x.zip This file includes
• STEP 7 V15 SP1 project
• SCL-sources
• SQL-driver-DLL
• License file
• SQL-script
„DEMO_MSSQL_V3.sql“
• ConfigDBCreator

3.4 Versioning and update of the driver


After installation the driver DLL is located in the ODK 1500S directory:
<$ProgramData>\Siemens\Automation\ODK1500S\ODK1500S_SQL.dll
You can identify the version of the driver DLL in the file properties (Windows
explorer → right click → properties)
The ODK1500S SQL driver is developed using the concept of semantic versioning:
• A version number consists of three parts: MAJOR.MINOR.PATCH, for
example 2.2.3
• A change of the PATCH version number means an error correction or
small functional extension that is fully compatible with earlier versions. To
update the driver it is sufficient to exchange the driver DLL
• A change of the MINOR version number means a functional extension.
There are new functions, but the old functions work as before. In this case,
the interface of the function blocks is often changed or extended. To
update the driver, it is therefore necessary to exchange the driver DLL and
update the function blocks. The FBs can be updated e.g. via the SCL
source supplied.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 12
3 Solution
3.4 Versioning and update of the driver

• A change of the MAJOR version number means that there are extensive
changes. Compatibility with earlier versions and firmware versions of the
CPU is usually lost. For upgrading, it is often necessary to update the
CPU-FW, as well as updating the driver FBs and replacing the driver DLL.
Figure 3-1 Properties of the driver DLL
© Siemens AG 2020 All rights reserved

NOTICE If the version of the installed DLL does not match the installed STEP 7 function
blocks, the following error code may returned:
0x8098 - ODK application could not be executed because the function is not
supported.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 13
3 Solution
3.5 New features and changes ODK 1500S SQL driver V3

3.5 New features and changes ODK 1500S SQL driver V3


The ODK1500S SQL driver V3 is a completely new development based on
ADO.NET and ODK1500S V2.5 and offers several advantages over previous
versions. Due to the new development, the user interface has also changed. The
most important changes and improvements are listed below:

• Each driver FB is now multi instance capable. Thus, different SQL commands
can be executed in parallel or e.g. data can be written in parallel to different
databases.
• The connection information for the driver FBs is specified by the user in the
PLC program via a "Connection String" parameter. A separate
parameterization of the ODBC driver as well as the handling of the data base
connections in the PLC program (Connect / Disconnect) by the user is
therefore not necessary anymore.
• There is only one placeholder for the arguments. Instead of the different
placeholders (%d, %s, %t...) for different data types the universal placeholder
"?" is used.
• Simplified error handling: Error messages are mostly also output as plain text
on the FBs. In addition, the number of error codes has been reduced to the
essential.
© Siemens AG 2020 All rights reserved

• ODK1500S SQL driver V3 is a 64-bit application (requires a 64-bit ODBC


driver)
• Output of log information FB-granular with the help of the Windows tool
“DebugView++”.
• Support of common databases

3.6 License mechanism


The driver is protected by a custom runtime license file. The license file is copied to
the PC running the S7-1500 Software Controller during installation process.
Each time the SQL driver is loaded, the license file is checked for validity. If the
license file is invalid, the loading process is terminated, an error code is output and
the functionality of the SQL driver FBs is lost.
The license file is a digitally signed XML file containing the following information:
• Address and company name of the license holder
• Date of issue
• Date of expiry
• Trial license (yes / no)
• Version SQL-driver (at date of issue)
• Application name
• Signature

The file can be viewed e.g. via a web browser to display information about the
expiration date of a trial license:

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 14
3 Solution
3.6 License mechanism

Figure 3-2: License file ODK1500S-sql-driver

The file must not be changed. If the file is manipulated, the signature loses its
validity and the SQL driver can no longer be used.
Depending on the license file the driver behaves as follows:
© Siemens AG 2020 All rights reserved

Table 3-5 Effects of License Mechanism


License status Description
1. Full license Full functionality

2. Trial license Full functionality


Inside trial period

3. Trial license No function, function block ODK1500S_SQL_V3_load


Trial period expired outputs error code “0xF000”

4. Manipulated license No function, function block ODK1500S_SQL_V3_load


file outputs error code “0xF001”

5. No license file No function, function block ODK1500S_SQL_V3_load


outputs error code “0xFFFF”

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 15
4 Function mechanisms
4.1 Overview of the functional principle

4 Function mechanisms
This chapter describes the function principle and function blocks of the ODK 1500S
SQL driver. Furthermore, we go into details concerning the establishment of the
connection to the SQL data server and the possible functions.
For the application of an SQL database with an S7-1500 Software Controller, there
are in total five function blocks available. These function blocks make it possible to:
• Load the driver DLL
• Establish the connection to the SQL server
• Execute SQL statements (e.g. insert, update, execute, select…)
• Write data to an SQL-database
• Read data from an SQL-database
• Close the connection to the database
• Unload the driver DLL

4.1 Overview of the functional principle


ODK 1500S SQL driver V3 offers two user interfaces to execute data base
operations from the STEP 7 user program.
© Siemens AG 2020 All rights reserved

Figure 4-1: Overview user interfaces

These interfaces will be provided by function blocks.

4.1.1 Write process data

Process data from a data block can be written to a database in a simple and high
performance manner using the block ODK1500S_SQL_V3_InsertUpdate. The
functional principle of this interface is shown in the following figure:
Figure 4-2: Functional principle FB ODK1500S_SQL_V3_InsertUpdate

The data, which shall be written in the database, can be provided to the FB as a
structure. Via input parameters it can be chosen whether data records shall be

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 16
4 Function mechanisms
4.2 Overview function blocks

overwritten (Update) or newly added to the database (Insert). In addition, the name
of the target table in the database can be parameterized.

4.1.2 Universal SQL interface

The function blocks ODK1500S_SQL_V3_Execute and


ODK1500S_SQL_V3_ExecuteSimple provide a universal SQL interface. This
interface can be used to execute any SQL statements for example to write data to
a database or request data from a database.
The actual data can be provided separately to the SQL statements (SQL String) via
a data block. The function principle is represented by a Select statement in the
following figure.

Figure 4-3: Functional principle FB ODK1500S_SQL_V3_Execute


© Siemens AG 2020 All rights reserved

4.2 Overview function blocks


The following table gives an overview of the function blocks belonging to the SQL
driver as well as their function.
Table 4-1: Overview function blocks SQL driver
Image Module name Function
ODK1500S_V3_Load Load SQL driver
DLL

ODK1500S_SQL_V3_ Execute SQL-


ExecuteStatementSimple statement (for
statements, that do
not return any
data)

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 17
4 Function mechanisms
4.2 Overview function blocks

Image Module name Function


ODK1500S_SQL_V3_ Execute SQL
Execute statement with
variable arguments
(allows to write and
read data via SQL
statements)

ODK1500S_SQL_V3_ Write data from a


InsertUpdate data block to an
SQL database
(without SQL
statement)
© Siemens AG 2020 All rights reserved

ODK1500S_SQL_V3_Unload Manual unloading


of DLL, e.g. for the
exchange of DLL

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 18
4 Function mechanisms
4.3 Description of the function blocks

4.3 Description of the function blocks


4.3.1 ODK1500S_SQL_V3_Load

Before using the SQL driver, it is necessary to load the supplied DLL with the
ODK1500_SQL_V3_Load block. In the delivered example application, the block
will be executed automatically.
By changing the edge (from 0 to 1) at the input parameter "REQ", the function is
started.

Figure 4-4: ODK1500S_SQ_V3L_Load block

Block parameter
© Siemens AG 2020 All rights reserved

Table 4-2: Parameter ODK1500S_SQL_V3_Load


Type Name Data Description
type
Input REQ BOOL A rising edge activates the loading of the SQL driver DLL.
Output DONE BOOL Indicates that the instruction to load the SQL driver DLL has
been terminated successfully.
Output BUSY BOOL Indicates that the SQL driver DLL is still being loaded.
Output ERROR BOOL Indicates that an error has occurred while loading the SQL driver
DLL. STATUS shows further information on the possible cause
of the error.
Output STATUS INT Gives information on possible sources of the error if an error has
occurred while loading the SQL driver DLL.

4.3.2 ODK1500S_SQL_V3_Execute

With the block ODK1500S_SQL_V3_Execute SQL statements can be sent to a


database. The connection is established using the connection information stored in
the parameter "sqlConnectionString". This function block can be called as often as
desired one after the other or in parallel as a multi-instance to execute among
others SELECT-, UPDATE-, INSERT- or DELETE-statements. An instruction is
operated asynchronously. Several PLC cycles are run to process and finish the
block.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 19
4 Function mechanisms
4.3 Description of the function blocks

Figure 4-5: ODK1500S_SQL_V3_Execute block


© Siemens AG 2020 All rights reserved

To prevent to convert the data (to be written into the database) to strings in the plc
program the actual data and the SQL statements can be passed separately to the
function block by using placeholders:
In this case the SQL statements of the application consist of two parts:
• SQL string: contains the SQL statement including placeholders for the SQL
arguments
• SQL argument: here, the actual data are defined
The block joins SQL string and SQL arguments and transmits the complete SQL
statement to the database.

Example SQL string:


SELECT year, test FROM ? WHERE titleid < ?
Whereat “?“ are the placeholders for the arguments:
? => “titles”
? => 5
The full statement for the database would then be interpreted as follows:
SELECT year, test FROM titles WHERE titleid < 5

The arguments are inserted for the place holders. Please consider with the
arguments that they should be in the same order as the place holders. The number
of arguments must match the number of placeholders.
The number of the place holders has to be equal to the number of the arguments.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 20
4 Function mechanisms
4.3 Description of the function blocks

NOTE The data and the SQL statements don’t necessarily have to be passed
separately to the function block. Alternatively, you can also pass the whole SQL
statement including the data to the input parameter “sqlString”. In this case you
have to use random supported datatype with the name “NoArgument”.
Alternatively, the block ODK1500S_SQL_V3_ExecuteSimple can be used.

An SQL statement is executed with a rising edge at the input „REQ“. In case of a
SELECT statement, the data requested from the database are read in addition and
via in the InOut Parameter “sqlReceivedData” provided. The data in interconnected
recieve data block must be in the same order as the data provided by the function
block of the database. If not enough data types are provided, an error message will
be displayed.

Block parameter
Table 4-3: Parameter ODK1500S_SQL_V3_Execute
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function.
Input sqlConnectionSt STRING Contains the necessary information for establishing the
ring connection. The connection string usually contains the name
© Siemens AG 2020 All rights reserved

of the ODBC driver, the IP address of the SQL server, the


name of the database, the username and the password.
Examples for common databases are stored in the example
project.
Input sqlString WSTRING SQL string contains the SQL statement with the defined
placeholders for the argument data. The maximum length of
the string is about 16000 characters.
Input connectionTime UINT Timeout in seconds for the connection establishment. If the
out connection to the database cannot be established within the
specified time, the execution of the FB is terminated.
Input commandTimeo UINT Timeout in seconds for the execution of SQL commands.
ut
Input enableDatetime Bool Sets fractional second precision to 3 digits to enable support
Support for "datetime" MS SQL datatype
Input enableLog BOOL Enables the output of log information. These can be read out
e.g. during commissioning with the help of the tool
DebugView++.
InOut sqlArgument VARIANT SQL argument: At this place, the data block has to be
connected to the structure for the according SQL statement.
This structure contains the data for the placeholders from the
SQL string.
InOut sqlConfigDataS Array [0.. Here, the data block must be connected to the structure with
end 1024] of the configuration data. The configuration data can be created
ODK1500S_ automatically using the included tool “ConfigDBCreator”
SQL_V3_typ using the sqlArguments. See Create configuration data block
eConfigData
InOut sqlReceivedDat VARIANT Here, a data block must be interconnected with the structure
a for the data returned by the database.
Output DONE BOOL This output value indicates that the instruction has
successfully terminated the execution of the ODK function.
Output BUSY BOOL This output value indicates that the instruction is still
executing the ODK function.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 21
4 Function mechanisms
4.3 Description of the function blocks

Type Name Data type Description


Output ERROR BOOL This output value indicates that an error has occurred during
the execution of the ODK function. The output value
STATUS gives further information on this matter.
Output STATUS INT This output value gives information on possible error sources
in case that an error has occurred during the execution of the
ODK function.
Output affectedRows DINT Number of rows changed or added in the database by the
execution of the SQL command.
Output fctError BOOL This output value indicates that an error occurred while
executing an SQL driver function. More information about
this is provided by the status values at the outputs
fctErrorCode and sqlErrorInfo.
Output fctErrorCode DWORD Sql function error code
Output sqlErrorInfo STRING Contains information about the occurred error from the SQL
database. The information depends on the used ODBC
driver or database.

4.3.3 ODK1500S_SQL_V3_ExecuteSimple

Alternatively, to the block ODK1500S_SQL_V3_Execute this block can be used to


© Siemens AG 2020 All rights reserved

execute any SQL statements that don’t request data from the database.

Figure 4-6: ODK1500S_SQL_V3_ExecuteStatmentSimple block

A SQL statement is executed with a rising edge at the input “REQ”.

Block parameter
Table 4-4: Parameter ODK1500S_SQL_V3_ExecuteStatmentSimple
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function.
Input sqlConnectionSt STRING Contains the necessary information for establishing the
ring connection. The connection string usually contains the name
of the ODBC driver, the IP address of the SQL server, the

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 22
4 Function mechanisms
4.3 Description of the function blocks

Type Name Data type Description


name of the database, the username and the password.
Examples for common databases are stored in the example
project.
Input sqlString WSTRING SQL string contains the SQL statement with the defined
placeholders for the argument data. The maximum length of
the string is about 16000 characters.
Input connectionTime UINT Timeout in seconds for the connection establishment. If the
out connection to the database cannot be established within the
specified time, the execution of the FB is terminated.
Input commandTimeo UINT Timeout in seconds for the execution of SQL commands.
ut
Input enableLog BOOL Enables the output of log information. These can be read out
e.g. during commissioning with the help of the tool
DebugView++.
Output DONE BOOL This output value indicates that the instruction has
successfully terminated the execution of the ODK function.
Output BUSY BOOL This output value indicates that the instruction is still
executing the ODK function.
Output ERROR BOOL This output value indicates that an error has occurred during
the execution of the ODK function. The output value
STATUS gives further information on this matter.
Output STATUS INT This output value gives information on possible error sources
© Siemens AG 2020 All rights reserved

in case that an error has occurred during the execution of the


ODK function.
Output affectedRows DINT Number of rows changed or added in the database by the
execution of the SQL command.
Output fctError BOOL This output value indicates that an error occurred while
executing an SQL driver function. More information about
this is provided by the status values at the outputs
fctErrorCode and sqlErrorInfo.
Output fctErrorCode DWORD Sql function error code
Output sqlErrorInfo STRING Contains information about the occurred error from the SQL
database. The information depends on the used ODBC
driver or database.

NOTE String data types must be formatted in the SQL-String with simple quotation
mark. This happens in the SQL-String with $'. For example: $'String$'

4.3.4 ODK1500S_SQL_V3_InsertUpdate

Data from a data block can be written to a database in a simple and high-
performance manner using the ODK1500S_SQL_V3_InsertUpdate block. The
block input parameters can be used to specify the table in the database in which
the data is to be written.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 23
4 Function mechanisms
4.3 Description of the function blocks

Figure 4-7: ODK1505S_SQL_V3_InsertUpdate Block


© Siemens AG 2020 All rights reserved

The data is written to the database with a rising edge at the input "REQ".

CAUTION Since the addressing of the data in the database is done by name, the names of
the variables from the data block connected to the input parameter sqlArguments
must match the names of the data in the database.
If this is not accomplished, an error message will be displayed.
The variable names are limited to 25 characters.

Block parameter
Table 4-5: Parameter ODK1500S_SQL_V3_InsertUpdate
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of
the ODK function.
Input sqlConnectionSt STRING Contains the necessary information for establishing the
ring connection. The connection string usually contains the name
of the ODBC driver, the IP address of the SQL server, the
name of the database, the username and the password.
Examples for common databases are stored in the example
project.
Input writeMode BYTE 0: Insert – Data is added to the target table, 1: Update – Data
is overwritten in the target table
Input tableName STRING Name of the table in the database where the data has to be
written / updated
Input updateCondition STRING Allows to specify the records to be updated at writeMode=1

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 24
4 Function mechanisms
4.3 Description of the function blocks

Type Name Data type Description


(Update). For example: „WHERE ID = 500“)
Input connectionTime UINT Timeout in seconds for the connection establishment. If the
out connection to the database cannot be established within the
specified time, the execution of the FB is terminated.
Input commandTimeo UINT Timeout in seconds for the execution of SQL commands.
ut
Input enableLog BOOL Enables the output of log information. These can be read out
e.g. during commissioning with the help of the tool
DebugView++.
Input enableDatetime Bool Sets fractional second precision to 3 digits to enable support
Support for "datetime" MS SQL datatype
InOut sqlArguments VARIANT SQL argument: Here, a data block must be interconnected
with the structure for the data to be written to the database.
The names of the variables must match with the names of
the data in the database
InOut sqlConfigData Array[0..102 Here the data block must be connected to the structure with
4] of the configuration data. The configuration data can be created
„ODK1500S automatically using the included tool "ConfigDBCreator"
_SQL_V3_ty using the sqlArguments. See Create configuration data block
peConfigDat
a
Output DONE BOOL This output value indicates that the statement has
© Siemens AG 2020 All rights reserved

successfully completed the execution of the ODK function.


Output BUSY BOOL This output value indicates that the statement is still
executing the ODK function.
Output ERROR BOOL This output value indicates that an error has occured during
the execution of the ODK function. For more information, the
output value is STATUS.
Output STATUS INT This output value provides information about possible error
sources when an error has occured during the execution of
the ODK function.
Output affectedRows DINT Number of rows changed or added in the database by the
execution of the SQL command.
Output fctError BOOL This output value indicates that an error occurred while
executing an SQL driver function. More information about
this is provided by the status values at the outputs
fctErrorCode and sqlErrorInfo.
Output fctErrorCode DWORD Sql function error code
Output sqlErrorInfo STRING Contains information about the occurred error from the SQL
database. The information depends on the used ODBC
driver or database.

4.3.5 ODK1500S_SQL_V3_Unload

This block makes it possible to manually unload the SQL driver DLL. Normally, this
is not necessary. Exception: If a new version of the SQL driver DLL shall be
installed, it must be unloaded before.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 25
4 Function mechanisms
4.4 Create configuration data block

Figure 4-8: ODK1500S_SQL_V3_Unload

Block parameter
Table 4-6: Parameter ODK1500S_SQL_V3_Unload
Type Name Data Description
type
Input REQ BOOL A rising edge activates the loading of the SQL driver DLL.
Output DONE BOOL Indicates that the instruction to load the SQL driver DLL has
been terminated successfully.
Output BUSY BOOL Indicates that the SQL driver DLL is still being loaded.
Output ERROR BOOL Indicates that an error has occurred while loading the SQL driver
© Siemens AG 2020 All rights reserved

DLL. STATUS shows further information on the possible cause


of the error.
Output STATUS INT Gives information on possible sources of the error if an error has
occurred while loading the SQL driver DLL.

4.4 Create configuration data block


The SQL driver requires information (data type and name) from the data to be
written to the database. Since the data is transferred internally to the SQL driver as
a Byte-Array, the information must be transferred separately via the input
parameter "sqlConfigData" when using the blocks
ODK1500S_SQL_V3_InsertUpdate or ODK1500S_SQL_V3_Execute. The
configuration data can be created automatically from a data block (sqlArguments)
using the included tool "ODK1500S ConfigDBCreator".

Figure 4-9: Operating principle of the configuration data block

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 26
4 Function mechanisms
4.4 Create configuration data block

The configuration data are generated in each case as an array with 1025 elements
of the plc data type "ODK1500S_SQL_V3_typeConfigData".

4.4.1 Example data block

The following figure shows various data, which shall be written into a database.
The data is summarized in a structure.

Figure 4-10_ SQL Arguments data block


© Siemens AG 2020 All rights reserved

The tool ODK1500S ConfigDBCreator generates a data block based on the data
block above with the configuration data for the three contained data structures.

Figure 4-11: Configuration data block

The configuration data contains the data type identifier as well as the name of the
variables.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 27
4 Function mechanisms
4.4 Create configuration data block

Figure 4-12: Configuration data for the insert structure from figure 4-14
© Siemens AG 2020 All rights reserved

The following table shows the data type identifiers for the supported STEP 7 data
types:

Table 4-7: data type identifiers for STEP 7 data types


STEP 7 data type identifier comment
BYTE#16#50 Identifier for string
String(n) BYTE#16#51 Identifier for string lentgh
(string length is passed via
name)
LInt BYTE#16#83
DInt BYTE#16#42
Int BYTE#16#22

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 28
4 Function mechanisms
4.4 Create configuration data block

STEP 7 data type identifier comment


SInt BYTE#16#13
Bool BYTE#16#01
LReal BYTE#16#85
Real BYTE#16#43
LReal BYTE#16#85
DTL BYTE #16#C1
BYTE#16#AA Has to be inserted after last
'EndOfArgument'
argument value

4.4.2 Create configuration data block with the ConfigDBCreator

The tool provides two ways to generate a configuration data block from the user
data (sqlArguments):
• Manual import and export of the data blocks
• Direct access to the TIA portal project using the ConfigDBCreator

Manual import and export of data blocks


The following steps must be executed:
• Export the data block with the data, which has to be written into the database
© Siemens AG 2020 All rights reserved

with all pendency as a source.

Figure 4-13: Export data block

• Generate configuration data block with the tool ConfigDBCreator (select the
exported data block as the DB source file and specify the destination path)

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 29
4 Function mechanisms
4.4 Create configuration data block

Figure 4-14: GUI ConfigDBCreator for manual Import and Export

• Import the generated configuration data block via external sources in the TIA
portal and generate the data block:

Figure 4-15: Import and generate configuration data block


© Siemens AG 2020 All rights reserved

After the configuration data block has been generated in the TIA portal, it is stored
in the Program blocks folder. The block always has the suffix "CFG". The
configuration data can then be interconnected with the input parameter
"sqlConfigData" from the block ODK1500S_SQLV3_ExecuteStatement or
ODK1500S_SQL_V3_InsertUpdate.

Direct Access to the TIA Portal Project using the ConfigDBCreator


The tool can directly access the TIA Portal project via the TIA Portal Openness
interface and can automatically and comfortably generate the configuration data
block.
A requirement for this is the installation of the free software TIA Portal Openness
on the engineering computer.
You can install TIA Portal Openness via the product DVD of STEP 7 Professional
V14SP1.

Figure 4-16: Approach Installation TIA Portal Openness

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 30
4 Function mechanisms
4.4 Create configuration data block

To use a TIA Portal Openness application the user has to be added once to the
"Siemens TIA Openness" user group:

Figure 4-17: User management


© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 31
4 Function mechanisms
4.4 Create configuration data block

After successful installation and configuration of TIA Openness, you can use the
ConfigDBCreator tool under the "TIA" tab to select a data block from which the
configuration data shall be created via the "Select project / block" button. After a
subsequent click on the "Create ConfigDB" button, a data block with the
configuration data will automatically be created in the actual opened TIA project.

Figure 4-18: GUI ConfigDBcreator with direct access to the TIA Project
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 32
4 Function mechanisms
4.4 Create configuration data block

Figure 4-19: Select data block

The configuration data block is now located in the Program blocks folder. The block
always has the suffix "CFG". The configuration data can then be interconnected
with the input parameter "sqlConfigData" from the block
ODK1500S_SQL_V3_Execute or ODK1500S_SQL_V3_InsertUpdate.
© Siemens AG 2020 All rights reserved

4.4.3 Restriction ODK1500S ConfigDBCreator

The tool supports optimized as well as non-optimized data blocks. Within the data
blocks all STEP 7 data types, structures, PLC data types supported by the SQL
driver, as well as arrays of elementary data types can be used.
Requirement is that the data for writing into the database are defined in a structure.
The following constellations are not supported because they are not supported by
the databases:
• Array of plc data type
• Nested structures
• Global constants (not supported for manual import/export)

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 33
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database

5 Installation and commissioning


This chapter describes the installation and commissioning of the ODK1500S-SQL
driver as well as the optional installation of the MSSQL database which belongs to
the S7-sample project.

5.1 Installation and commissioning of the MSSQL demo


database
The following installation instructions help to configure the demo database being
supplied with the ODK1500S_SQL driver as well as to install an MS-SQL Express
server.

5.1.1 Installation MSSQL Server 2014 Express and Tools

The database system “Microsoft SQL 2014 Server Express and Tools“ is installed
on the database server. To install the database, the file „SQLEXPRWT_x64_ENU“
is executed. The environment language of the operating system and the data
management system must match. Under the item installation a „New SQL Server
stand-alone installation“ is selected:
Figure 5-1: Installation center
© Siemens AG 2020 All rights reserved

The next steps are self-explanatory. Here, the license conditions have to be
accepted and you have to click continue until the item “feature selection”.
As demonstrated in the following figure, at least the following components have to
be selected:

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 34
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database

Figure 5-2: Feature Selection


© Siemens AG 2020 All rights reserved

The named instance is kept for the sample project:


Figure 5-3: Named instance

With the server configuration, the network service is selected. For the sample
project, the SQL server service is sufficient:

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 35
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database

Figure 5-4: Server Configuration


© Siemens AG 2020 All rights reserved

Making a Windows and a server login possible, you have to select the mixed
service in the following figure during the configuration of the data blocks.
Furthermore, a server password as well as a server administration has to be
defined. The settings for errors and administration reports, which will be available
in the next window, are not used for this example. After the summary, the SQL
server is installed by pushing the key “install”.

Figure 5-5: Database Engine Configuration

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 36
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database

5.1.2 Configuration of the SQL server

After the SQL server has been installed, the communication to the runtime PC (S7-
Software Controller) has to be configured. For this, the SQL server configuration
manager has to be opened first. This is done via Start→Program→ Microsoft SQL
Server 2014 →configuration tools→ SQL Server configuration. After that, you can
see under the menu item SQL server services which services are executed. Doing
so, please consider that the SQL server service is active:
Figure 5-6: SQL server services

Then, the TCP/IP connection is activated and configured. Via SQL server network
configuration -> protocols for SQLEXPRESS -> TCP/IP -> right mouse key ->
properties, this step can be executed. Under the tab protocol, the TCP/IP
communication can be activated. Under IP addresses, a static IP address as well
as a port (for example 2301) has to be entered. After that, the service hast to be
started again.
© Siemens AG 2020 All rights reserved

Figure 5-7: TCP/IP settings

Note The settings only become effective when the according service has been started
again.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 37
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database

5.1.3 Generation of the sample database by a script

The provided script “DEMO_MSSQL_V3.sql” creates a demo database with a


demo table, a user login with password and a user for the demo database. The
script can be executed from a local directory as well as from an USB flash drive.
By double-click the script could be executed on the database server, where SQL
Server Management Studio is already installed. Therefore a login as administrator
is necessary. After the script execution the SQL Server Management Studio
automatically starts and a connection to the server “SQLEXPRESS” with Windows
Authentication should be established (figure 5-8)

NOTE Please note that you have to establish a connection to the server
“SQLEXPRESS” before executing the script.

Figure 5-8: Login with Windows Authentication


© Siemens AG 2020 All rights reserved

After a successful connection to “SQLEXPRESS” the script is seen in the tab on


the right side. By using the command “Execute” the script is executed.

Figure 5-9: Execute the script

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 38
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database

After the commands were successfully completed the following components will be
created:
• DEMO_MSSQL_DATABASE: demo database with demo table
• User login: odk1500s with password 1234. The connection to the SQL
server can be realized via the Windows authentication or via an SQL
server authentication. For a remote connection via TCP/IP, the SQL server
authentication is required. For this, a user login has to be generated. After
the new login has been defines, you can choose between the Windows
and the SQL Server authentication by the next establishment of the
connection.
• User odk1500s for the demo database

Figure 5-10: Commands completed successfully


© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 39
5 Installation and commissioning
5.2 Installation and commissioning of the SQL driver on the runtime PC

5.2 Installation and commissioning of the SQL driver on


the runtime PC
In the following you can find a description of the installation of the ODK1500S-SQL
driver on the runtime PC (S7-1500 Software Controller).

5.2.1 Installation of the SQL driver DLL

The installation of the SQL driver for the SQL database connection is limited to the
execution of the Install_Odk1500S-SQL.bat file as administrator. During the
installation, the DLL has to be located in the same directory as the SQL_install.bat
file.

NOTICE The Install_Odk1500S-SQL.bat file must be executed as administrator on


Windows. Otherwise, the required files are not copied to the destination folder.

5.2.2 Configuration of the ODBC driver

A 64-bit ODBC driver is required for the connection to the SQL database. This
driver must be installed on the runtime PC. It is recommended to use rather new
(e.g. latest release) ODBC drivers than older versions.
© Siemens AG 2020 All rights reserved

A parameterization of the ODBC driver is no longer necessary from version 3.0 of


the ODK1500S SQL driver, since the connection to the database is established via
the connection information in the connection string.
For best performance, it is strongly recommended to activate “Connection Pooling”.
This can be activated for the respective ODBC driver via the tab "Connection
Pooling" in the "ODBC Data Source Administrator" tool:

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 40
5 Installation and commissioning
5.2 Installation and commissioning of the SQL driver on the runtime PC

Figure 5-11: ODBC driver connection pooling configuration


© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 41
6 Operation of the application
6.1 Use of the example application

6 Operation of the application


6.1 Use of the example application
The ODK1500S SQL driver comes with a sample application that shows how the
SQL driver function blocks can be used to write data to the demo database, modify
data or read data from the database.
The sample application consists of the following components:
• MSSQL demo database „DEMO_MSSQL_DATABASE“
• STEP 7 V15 SP1 professional sample project

First, install and configure the demo database and the SQL driver as described in
chapter Installation and commissioning.
Dearchive the supplied STEP 7 sample project and adapt the hardware
configuration to your applied components and settings, if necessary. After that,
load the project to your controller.
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 42
6 Operation of the application
6.1 Use of the example application

6.1.1 Structure of the STEP 7 example project

Figure 6-1: Structure of the example project


© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 43
6 Operation of the application
6.1 Use of the example application

The sample project consists of the ODK1500S_SQL- function blocks, PLC-data


types as well as interface data blocks where, among others, the SQL strings and
SQL arguments can be stored. In the following you can find a description of the
single components:

Organization blocks
• Main (OB1): Call of the sql driver function blocks

Function blocks
• ODK1500S_SQL_V3_Load
• ODK1500S_SQL_V3_Execute
• ODK1500S_SQL_V3_ExecuteSimpel
• ODK1500S_SQL_V3_InsertUpdate
• ODK1500S_SQL_V3_Unload

Data blocks
• ODK1500S_SQL_V3_ConnectionsStrings: The connection information for
establishing a connection to the database is stored here
• ODK1500S_SQL_V3_ARGUMENTS: Here, the SQL arguments are indicated.
(Data, which hast to be written into the data base).
© Siemens AG 2020 All rights reserved

• ODK1500S_SQL_V3_ARGUMENTS_CFG: contains the configuration data for


the SQL arguments (created using the ConfigDBCreator tool from DB
ODK1500S_SQL_V3_ARGUMENTS)
• ODK1500S_SQL_V3_STRINGS: here, the SQL strings for the SQL statements
are specified.
• ODK1500S_SQL_V3_SELECTED_DATA: here, the values of e.g. a SQL
Select statement returned by the database are stored
• ODK1500S_SQL_V3_CONROL_DB: central control and watch data block in
the example application

PLC data types


• ODK1500S_SQL_V3_typeConfigData: structure for the configuration data that
are created from the SQL arguments using the ConfigDBCreator tool
• typeWindowsDiag: Optional: Used in data block “WindowsDiag” to provide
diagnostic information about the Windows operating system

Watch table
• ODK1500S_SQL_V3_ControlTable: Watch table to control the example
application (contains variables from the DB
ODK1500S_SQL_V3_CONTROL_DB)

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 44
6 Operation of the application
6.1 Use of the example application

Figure 6-2: Watch table „ODK1500S_SQL_V3_ControlTable“


© Siemens AG 2020 All rights reserved

6.1.2 Loading of SQL driver DLL

Before you can use the ODK1500S-SQL driver, it is necessary to load the SQL
driver DLL from the software controller.
The SQL driver DLL is automatically loaded in the sample project as soon as there
is a connection between the software controller and Windows OS.
For this purpose the block "GetWindowsDiag" is called in OB1. This provides the
state of the Windows operating system via an InOut structure. Within this structure,
the bit "WindowsIsRunning" is stored. This bit is connected to the "REQ" input of
the ODK1500S_SQL_V3_Load block.
Only when the SQL driver DLL shall be exchanged by a new version it might
become necessary to unload the loaded DLL, to install the new version of the DLL
and then manually load the new version.
To manually load the DLL, please proceed as follows:
• Open the watch table ODK1500S_V3_ControlTable
• Modify the bit
"ODK1500S_SQL_CONTROL_DB.ODK1500S_SQL_V3_Load.REQ“ to 1
The function block ODK1500S_SQL_V3_Load is called in the OB1.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 45
6 Operation of the application
6.1 Use of the example application

6.1.3 Execution of SQL statements

With the block ODK1500S_ODK_SQL_V3_Execute SQL statements with flexible


arguments can be executed.
The general proceeding to execute SQL statements in the example application
consists of two steps:
1. Select the desired SQL statement
2. Select the request bit of the SetStatement function
For this, please open the watch table ODK1500S_SQL_V3_ControlTable first:

For the example application, the SQL statements being defined in the data blocks
ODK1500S_SQL_V3_STRINGS and ODK1500S_SQL_V3_ARGUMENTS are
used.

Note For the correct functioning of the example application, please ensure that only
one SQL statement is selected in the watch table!

Execution of an SQL INSERT or SELECT statement


• If necessary, reset the selection of a different SQL statement

© Siemens AG 2020 All rights reserved

According to the desired example SQL statement, modify the bit


"ODK1500S_SQL_V3_CONTROL_DB.SQL_Insert“ or
"ODK1500S_SQL_V3_CONTROL_DB.SQL_Select“ to 1
• Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_V3_Execute.REQ“ to 1
The function block ODK1500S_SQL_SetStatement is called in the OB1. After the
successful execution, the bit "
ODK1500S_SQL_V3_CONTROL_DB.ODK1500S_SQL_V3_Execute.REQ“ is
reset again.

6.1.4 Write process data

The ODK1500S_SQL_V3_insertUpdate function block can be used to write data


from a data block without SQL strings (SQL statements) to the database
• If necessary, reset another SQL statement
• Depending on the desired function, control the bit
"ODK1500S_SQL_V3_CONTROL_DB.SQL_Insert" (insert a new data record
into the database) or "ODK1500S_SQL_V3_CONTROL_DB.SQL_Update" to 1
(updates / overwrites the data record with ID 500 in the database)
• Set the bit
"ODK1500S_SQL_V3_CONTROL_DB.ODK1500S_SQL_V3_InsertUpdate.RE
Q" to 1
The block ODK1500S_SQL_V3_InsertUpdate is called in OB1. After successful
execution, the bit
"ODK1500S_SQL_V3_CONTROL_DB.ODK1500S_SQL_V3_InsertUpdate.REQ"
is reset again.

6.1.5 Unload SQL driver DLL

A manual unloading is only necessary in case of exchanging the DLL. Doing so,
please proceed as follows:

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 46
6 Operation of the application
6.2 Adaption of the example application to own requirements

• Open the watch table ODK1500S_SQL_V3_ControlTable


• Modify the bit
"ODK1500S_SQL_V3_CONTROL_DB.ODK1500S_SQL_V3_Unload.REQ“ to
1
The function block ODK1500S_SQL_V3_Unload is called in the OB1.
After you have exchanged the SQL drivers dll for a new version, you can reset the
ODK1500S_SQL_V3_CONTROL_DB.ODK1500S_SQL_V3_Unload.REQ bit. The
new SQL driver dll is automatically loaded in the demo application.

6.1.6 Error analysis

If the execution of an SQL function block was not successful, the error codes which
are returned by the blocks, can be monitored online in the data block
SQL_CONTROL_DB.
For detailed information concerning the error codes, please refer to chapter 7.

6.2 Adaption of the example application to own


requirements
We recommend using the STEP 7 sample project at first and then adapt it to your
own requirements.
© Siemens AG 2020 All rights reserved

NOTE Experienced STEP 7 programmers can alternatively use the provided SCL-
source file which contains the function blocks of the ODK 1500S SQL driver
instead of using the sample project.

6.2.1 Adaption of the connection information

To do this, adjust the connection information in the data block


ODK1500S_SQL_V3_ConnectionStrings that is required for the connection to your
database. Orientate yourself on the syntax of the examples in the data block
ODK1500S_SQL_V3_ConnectionStrings.
• Driver: name of the ODBC driver to be used (e.g. "ODBC Driver 17 for
SQL Server")
• server: IP address and name of the server (e.g.
"192.168.0.211\SQLEXPRESS")
• Database: Name of the database (e.g. "DEMO_MSSQL_DATABASE")
• Uid: Username for the login
• Pwd: Password for the login

6.2.2 Adaption of the SQL statements

As described before, SQL statements consist of two parts:


• SQL string: contains the SQL statement including placeholders (“?”) for the
SQL arguments
• SQL argument: here, the actual data is defined

1. Enter your sql statement in the data block ODK1500S_SQL_V3_STRINGS


including the placeholders for the arguments. The maximal SQL string length is
about 16000 characters.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 47
6 Operation of the application
6.2 Adaption of the example application to own requirements

2. In data block ODK1500S_SQL_V3_ARGUMENTS define a structure with the


data, in the same order as the placeholders in the SQL string.
3. Use the ConfigDBCreator tool to generate the configuration data for the
ODK1500S_SQL_V3_ARGUMENTS block. See Create configuration data
block.
The three data blocks resp. the structures have to be passed to the block
ODK1500S_SQL_V3_Execute.
If you use a SQL select statement, please adapt accordingly the order and the
structure of the data in the data block ODK1500S_SQL_V3_ SELECTED_DATA.
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 48
7 Status and Error codes
7.1 Status and Error Codes ODK1500S

7 Status and Error codes


7.1 Status and Error Codes ODK1500S
The ODK1500S-SQL driver has been developed with the ODK1500S (Open
Development Kit). The ODK can also generate status and error codes which are
returned to the function blocks at the output „STATUS“.

Table 7-1: ODK Status and Error Codes


Status Description
Codes
(HEX)
0x0000 Success
(Un)Load the ODK driver
No active (un)loading
0x7000
Execute the ODK driver
No active process
(Un)Load the ODK driver
(Un)Loading in progress, first call
© Siemens AG 2020 All rights reserved

0x7001
Execute the ODK driver
First call (asynchronous)
(Un)Load the ODK driver
(Un)Loading in progress, ongoing call
0x7002
Execute the ODK driver
Continuous call (asynchronous)
Load the ODK driver
0x7100
CPU function library is already loaded
Error Description
Codes
(HEX)
Load the ODK driver
CPU function library could not be loaded. An exception occurred during
execution of the "OnLoad()" function.

Execute the ODK driver


0x8090 CPU function library could not be executed. An error occurred during
execution.

Unload the ODK driver


An exception occurred during the unloading of the CPU function library.
The CPU function library has been unloaded nevertheless.
Execute the ODK driver
0x8091 CPU function library could not be executed. A "STOP" occurred during
the function call.
Load the ODK driver
0x8092
CPU function library could not be loaded because the library name is invalid.
0x8093 Load the ODK driver

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 49
7 Status and Error codes
7.1 Status and Error Codes ODK1500S

CPU function library could not be loaded because the CPU function library could not be
found. Check the file name and path of the file.
Load the ODK driver
0x8094 CPU function library could not be loaded. The CPU function library was created for the
Windows user context, but no user is logged on.
Load the ODK driver
CPU function library could not be loaded due to the following reasons:
• The DLL file is not a CPU function library
• An attempt has been made to load a 64-bit application into a 32-bit
system
0x8095
• Dependencies on other Windows DLL files could not be resolved.
– Check that the release build of the CPU function library is used.
– Check whether the "Visual C++ Redistributables" are installed
for the Visual Studio version you are using.
• The CPU does not support the utilized ODK version.
Load the ODK driver
The CPU function library could not be loaded because the internal
identification is already being used by another loaded CPU function
library.

Execute the ODK driver


0x8096
CPU function library could not be executed because the
© Siemens AG 2020 All rights reserved

CPU function library was not loaded or unloading is not yet finished.

Unload the ODK driver


CPU function library could not be unloaded because the
CPU function library was not loaded or unloading is not yet finished.
Load the ODK driver
The CPU function library could not be loaded because the
CPU function library is currently being unloaded.
0x8098
Execute the ODK driver
CPU function library could not be executed because the function is not
supported.
Execute the ODK driver
CPU function library could not be executed because the maximum
0x8099
amount of input data (1 MB) was exceeded (declarations with "In" and
"InOut")
Execute the ODK driver
CPU function library could not be executed because the maximum
0x809A
amount of output data (1 MB) was exceeded (declarations with "Out"
and "InOut")
(Un)Load the ODK driver
The CPU function library could not be (un)loaded and returns an invalid
value (the values 0x0000 and 0xF000 - 0xFFFF are allowed)
0x809B
Execute the ODK driver
The function returns an invalid value (a value between 0x0000 and
0x6FFF; 0xF000 and 0xFFFF is permitted)
Function uses an invalid data type:
0x809C • IN_DATA
• INOUT_DATA

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 50
7 Status and Error codes
0

• OUT_DATA
Load the ODK driver
CPU function library could not be loaded.
Start the ODK service manually or restart Windows.

Execute the ODK driver


CPU function library could not be executed for the following reasons:
• The "<STEP7Prefix>_Unload" instruction was executed during a
function execution. The function execution was aborted at the CPU
end. Windows terminates the execution of the function normally. No
return value is sent to the CPU.
0x80A4
Wait until the "<STEP7Prefix>_Unload" instruction has ended. Then
load the CPU function library again.
• Windows is not available
• ODK service is not running
Start the ODK service manually or restart Windows.

Unload the ODK driver


CPU function library could not be unloaded for the following reasons:
• Windows is not available
Start the ODK service manually or restart Windows.
(Un)Load the ODK driver
© Siemens AG 2020 All rights reserved

CPU function library could not be (un)loaded. There are currently not
enough resources available from Windows.
Reload the CPU function library after a few seconds.
0x80C2
Execute the ODK driver
CPU function library could not be executed. The CPU currently does
not have enough resources.
Execute the CPU function library again after a few seconds.
(Un)Load the ODK driver
CPU function library could not be (un)loaded. The CPU currently does
not have enough resources.
Reload the CPU function library after a few seconds.
0x80C3
Execute the ODK driver
CPU function library could not be executed. The CPU currently does
not have enough resources.
Execute the CPU function library again after a few seconds.
0xF000 Load the ODK driver
ODK1500S SQL driver license file is expired. Please purchase a full license
Load the ODK driver
0xF001
ODK1500S SQL driver license file is invalid. (The license file must not be manipulated!)
Load the ODK driver
0xFFFF
ODK1500S SQL driver license file does not exist in ODK1500S folder

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 51
7 Status and Error codes
7.2 Error Codes ODK1500S SQL driver

7.2 Error Codes ODK1500S SQL driver


7.2.1 Function Error Codes

These messages describe errors in the ODK functions of the SQL driver. For
example if a data type in a data block does not match a value read from the
database. The error code is output at output "fctErrorCode". In case of an error the
output bit “fctError” is set.

Tabelle 7-2: Function Error Codes


Error- Description
Code
The argument Config Data (sqlArgumentsConfigData) contains a not supported data type
9500
identifier.
The length of the data at parameter sqlArguments does not match the length of the data in
9501
sqlArgumentsConfigData
An exception occurred while checking the Config data. For further information please check
9502
sqlErrorInfo.
An exception occurred while reading the arguments (sqlArguments). For further information
9503
please check sqlErrorInfo.
The data received from the database exceeds the size of the data at parameter
9510
© Siemens AG 2020 All rights reserved

sqlReceivedData.
9511 The data received from the database contains an unsupported data type.
An exception occurred when writing the received data (sqlReceivedData). For further
9512
information please check sqlErrorInfo.
An exception occurred while checking the length of the received data. For further
9513
information please check sqlErrorInfo.
9514 The length of the received blob data exceeds the maximum length of 65535 bytes.
The number of characters returned in a Sting from the database is greater than the
9515
maximum supported length of 254 characters.
An exception occurred while executing the SQL statement. For more information please
9520
check sqlErrorInfo.
9521 The parameter tableName must not be empty.
9530 Invalid value at parameter writeMode. Value must be 0 (Insert) or 1 (Update).

7.2.2 SQL Error Info

At the output sqlErrorInfo the error message is output as plain text. The error
messages may vary depending on the database and ODBC driver.
Warnings or hints are also output here. In this case, the output fctError is not set.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 52
8 Output and display of log information
8.1

8 Output and display of log information


The logging function of the SQL driver helps to configure the SQL statements and
to check the messages sent and received by the driver. It also displays any error
messages that occur. It is also possible to export the log information to a file.
To display the log information on the runtime computer, you can use e.g. the free
open source tool "DebugView++". This tool can be downloaded under the following
link:https://github.com/CobaltFusion/DebugViewPP/releases

The current 64-bit release version (DebugView++.zip) is recommended.

Operation
Copy the tool on the runtime computer (IPC running the S7-1500 Software
Controller) and start the tool with administrator rights.
To receive the log output from the SQL driver you have to define the log settings as
follows:

Figure 8-1: Log-settings


© Siemens AG 2020 All rights reserved

To get only log information from the SQL driver it is also recommended to set the
filter to the "ODK_Host_x64.exe" process via the filter button as follows:

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 53
8 Output and display of log information
8.1

Figure 8-2: filter settings DebugView++

Now, all SQL driver blocks will output log information for which the "enableLog"
© Siemens AG 2020 All rights reserved

parameter is activated. The log information is buffered in the SQL driver and is only
output when the processing of the function block is completed. This ensures that
the log information is consistent when SQL driver function blocks are executed in
parallel.

Figure 8-3: Output sql driver log informationen with DebugView++

With the menu item File->SaveLog the log information can be saved to a file.

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 54
9 Related literature

9 Related literature
Table 9-1
Topic Title / Link
\1\ Siemens Industry http://support.industry.siemens.com
Online Support
\2\ Download page of https://support.industry.siemens.com/cs/ww/en/view/109479140
this entry
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 55
10 Contact partner

10 Contact partner
For questions about the ODK1500S SQL driver or problems with the application,
you can submit a support request via the following email address:
applications.aud.koe.nrh.rd@siemens.com
© Siemens AG 2020 All rights reserved

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 56
11 History

11 History
Table 11-1
Version Date Modifications
V1.0 08/2015 First version
V1.1 06/2016 Support of 64-bit floating point numbers
Direct input of SQL Statements possible (Separation
between data and string not necessary)
V2.0 06/2017 Implementation with ODK1500S V2
New user interface
New function block for writing process data without SQL
strings/statements
New function bock for executing SQL statements without
arguments
Support of optimized data blocks
Support for additional data types (datetime, bit…)
SQL statements with up to 16000 characters in the user
program
V2.1 08/2017 Support of unicode datatypes WString resp. nvarchar
Support of variable string length in read and write direction
Increased data interface from 8kByte to 265 kByte
(sqlArguments / sqlReceivedData)
© Siemens AG 2020 All rights reserved

Improved diagnostic with SQL Viewer


Bugfixes
V2.2 10/2018 Timeout parameter for FB Connect und ExecuteStatement
compatibility mode for MS SQL "datetime" datatype
Output of a warning as well as detail information via
SQLViewer if a value with the content "NULL" is read out via
a select statement
Bugfixes
V2.3 05/2020 Support of BLOB datatypes, information about versioning
V3.0 10/2020 Adapted documentation for ODK1500S SQL driver V3
V3.0 10/2020 Update: Added information for oracle database
V3.1 12/2020 Document: added information for PostgreSQL datatypes
Driver:
Support for variable string length for varchar and nvarchar
Microsoft sql datatypes in read direction
Optimized block interface for driver blocks to reduce data-
work-memory in plc

ODK 1500S-SQL-driver
Entry-ID: 109479140, V3.1, 12/2020 57

You might also like