Professional Documents
Culture Documents
Connection of an SQL
database to an S7-1500
Software Controller
SIMATIC ODK 1500S-SQL-driver V1.0
https://support.industry.siemens.com/cs/ww/en/view/109479140
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 2015 All rights reserved
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, V1.0, 08/2015 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 Validity .................................................................................................. 7
3.3.2 Used components ................................................................................ 7
4 Function mechanisms ....................................................................................... 9
4.1 Overview............................................................................................... 9
4.2 Description of the function blocks ...................................................... 11
4.2.1 ODK1500S_SQL_Load ...................................................................... 11
4.2.2 ODK1500S_SQL_Connect................................................................. 11
4.2.3 ODK1500S_SQL_SetStatement ........................................................ 13
4.2.4 ODK1500S_SQL_GetData................................................................. 16
4.2.5 ODK1500S_SQL_GetBlob ................................................................. 19
4.2.6 ODK1500S_SQL_Disconnect ............................................................ 22
Siemens AG 2015 All rights reserved
4.2.7 ODK1500S_SQL_Unload................................................................... 23
5 Installation and commissioning ..................................................................... 24
5.1 Installation and commissioning of the MSSQL demo database......... 24
5.1.1 Installation MSSQL Server 2014 Express .......................................... 24
5.1.2 Configuration of the SQL server ......................................................... 27
5.1.3 Restoration of the sample scheme ..................................................... 28
5.1.4 Generation of a login to the SQL server ............................................. 29
5.2 Installation and commissioning of the SQL driver on the runtime
PC....................................................................................................... 31
5.2.1 Installation of the SQL driver DLL ...................................................... 31
5.2.2 Parameterization of the ODBC driver ................................................. 31
6 Operation of the application ........................................................................... 35
6.1 Use of the example application .......................................................... 35
6.1.1 Structure of the STEP 7 example project ........................................... 36
6.1.2 Loading of SQL driver DLL ................................................................. 38
6.1.3 Establish the connection to the database .......................................... 38
6.1.4 Transmission of SQL statements ....................................................... 38
6.1.5 Disconnect the connection to the database ....................................... 39
6.1.6 Unload SQL driver DLL ...................................................................... 39
6.1.7 Error analysis ..................................................................................... 39
6.2 Adaption of the example application to own requirements ................ 40
6.2.1 Adaption of the ODBC-Login data ...................................................... 40
6.2.2 Adaption of the SQL statements ........................................................ 40
7 Error codes ....................................................................................................... 41
7.1 Overview............................................................................................. 41
7.2 Error Codes ODK1500S ..................................................................... 42
7.3 Error Codes ODK1500S SQL driver .................................................. 43
7.3.1 Function Error Codes ......................................................................... 43
7.3.2 ODBC Function Number .................................................................... 44
7.3.3 ODBC Function Error Code................................................................ 45
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 3
Table of contents
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 4
1 Introduction
1 Introduction
This document describes the connection of an SQL-database to an S7-1500
Software Controller with ODK1500S-SQL-driver.
Among others, you will find a description of how to send SQL-statements to and
how to call data from the SQL server by means of the driver.
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 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 for
the production of a certain product series, from a central database.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 6
3 Solution
3.1 Overview
3 Solution
3.1 Overview
The on-board equipment is not sufficient to connect a database to an S7-1500
controller.
To solve this problem, an SQL driver for the S7-1500 software controller has been
developed with the 1500S ODK (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.
In general, the driver can be used for databases with an ODBC driver.
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 and STEP 7 V13 is assumed.
Note Officially, the SQL driver only supports the four mentioned SQL statements.
These statements have been tested and released. In addition to these
statements, there are generally further SQL statements that function, 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 software
controller, directly to the SQL database.
This application has been generated and checked with the following components:
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 7
3 Solution
3.3 Hardware and software components
Hardware components
Table 3-1
Component No. Order number Note
1515SP PC 1 6ES7 677-2AAxx-0xx0 ET 200SP Open Controller
Software components
Table 3-2
Component No. Order number Note
STEP 7 1 6ES7 822-1AA03-0YA5
Professional V13
SP1
Microsoft SQL 2014 1 https://www.microsoft.com/en- As an alternative,
Server Express US/download/details.aspx?id= Microsoft SQL 2008 R2
Edition 42299 Server Express Edition,
for example, can be used
as well
CPU 1505S FW 1.7 1 6ES7 672-5AC00-0YA0 As an alternative, each
available S7-1500
Software Controller can
be used.
Siemens AG 2015 All rights reserved
SQL-driver-DLL 1 Windows-DLL
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 8
4 Function mechanisms
4.1 Overview
4 Function mechanisms
This chapter describes the function blocks for the establishment of the connection
to the SQL server as well as for the SQL statements. 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 seven function blocks available. These function blocks make it possible
to:
load the driver DLL
establish the connection to the SQL server
transmit SQL statements
read data from the database
close the connection to the database
unload the driver DLL
4.1 Overview
The following table gives an overview of the function blocks belonging to the SQL
driver as well as their function.
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 9
4 Function mechanisms
4.1 Overview
ODK1500S_SQL_Disconnect Disconnect
connection to the
SQL-Server
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 10
4 Function mechanisms
4.2 Description of the function blocks
Before using the SQL driver, it is necessary to load the supplied DLL with the
ODK_Load block.
By changing the edge (from 0 to 1) at the input parameter "REQ", the function is
started.
Block parameters
Table 4-2: Parameter ODK1500S_SQL_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.2.2 ODK1500S_SQL_Connect
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 11
4 Function mechanisms
4.2 Description of the function blocks
Module parameter
Table 4-3: Parameter ODK1500S_SQL_Connect
Type Name Data type Description
Siemens AG 2015 All rights reserved
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function.
Input odbcSystDSN STRING ODBC Data Source Name
Input username STRING User name for the login to the SQL database
Input password STRING Password for the login to the SQL database
Input enableDebug BOOL Activates the commissioning mode which can be used to
output expanded diagnostics information by means of the
SQL viewer tool.
Output DONE BOOL This output value indicates that the instruction to execute the
ODK function has been terminated successfully.
Output BUSY BOOL This output value indicates that the ODK function is still being
executed.
Output ERROR BOOL This output value indicates that an error has occurred during
the execution of the ODK function. The output value
STATUS shows further information on this matter.
Output STATUS INT This output value gives information on possible sources of
the error if an error has occurred during the execution of the
ODK function.
Output fctError BOOL This output value indicates that an error has occurred during
the execution of an SQL driver function. The status values at
the outputs FctErCode, odbcFctErCode, odbcFctNr,
sqlErCodes give further information on this matter.
Output fctWarning BOOL This output value indicates that a warning message has been
shown during the execution of an SQL driver function. The
status values at the outputs FctErCode, odbcFctErCode,
odbcFctNr, sqlErCodes give further information on this
matter.
Output debugActive BOOL This output value indicates if the commissioning mode is
active.
Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver
function
Output odbcFctNr DWORD Error code of the SQL driver: Number of the called ODBC
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 12
4 Function mechanisms
4.2 Description of the function blocks
4.2.3 ODK1500S_SQL_SetStatement
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 13
4 Function mechanisms
4.2 Description of the function blocks
%s => titles
%d => 5
The full statement for the database would then be interpreted as follows:
SELECT year, test
FROM titles
WHERE titleid < 5
The arguments are entered for the corresponding dummies, but the length of the
single arguments is limited to the according data type. In the special case of
STRING, it is possible to use up to 254 characters for each argument. Please
consider with the arguments that they are in the same order as the dummies.
Errors are indicated as soon as the data type does not correspond to the dummy.
The following table shows the corresponding dummies and data types.
Table 4-4: corresponding data types and dummies
Data types Place holders PLC data type
INTEGER %d ODK1500S_SQL_DataTypeInteger
SMALLINT %d ODK1500S_SQL_DataTypeSmallInteger
REAL %f ODK1500S_SQL_DataTypeReal
CHAR
%s ODK1500S_SQL_DataTypeChar
Siemens AG 2015 All rights reserved
(STRING)
The number of the dummies has to correspond to that of the arguments as well. To
achieve conformity, it is necessary to use the four pre-defined PLC data types
which correspond to the above mentioned data types. As the first information, the
PLC data types contain the data type as a defined number, where 1 stands for
INTEGER, 2 for SMALLINT, 4 for REAL and 5 for CHAR (STRING). The SQL
data type DOUBLE with 64 Bit is changed into STEP 7 REAL data type with 32 Bit.
As the second information, the value of the argument is stored in the corresponding
data format. The following figure shows the SQL-PLC data type STRING.
Figure 4-4: PLC data type String
ATTENTION In STEP 7, strings are marked with '. However, SQL requires ' as well.
Thus, to be able to represent a string in SQL, you have to put before and
after the $: ('$'String$'').
An SQL statement is transmitted with a rising edge at the input REQ. In case of a
SELECT statement, the data requested from the database are read in addition.
Module parameter
Table 4-5: Parameter ODK1500S_SQL_SetStatement
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function.
Input sqlString WSTRING SQL string, contains the SQL statement with the defined
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 14
4 Function mechanisms
4.2 Description of the function blocks
The following figure shows a data block with SQL strings for the four possible SQL
statements. One string can be connected to the input SQL string.
Figure 4-5: Data block with SQL strings
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 15
4 Function mechanisms
4.2 Description of the function blocks
The following figure shows a data block with SQL arguments for the four possible
SQL statements. These ones can be connected to the input SQL argument.
Figure 4-6: data blocks with SQL arguments
Siemens AG 2015 All rights reserved
ATTENTION The data block, which is connected to the input parameter SQL
ARGUMENT, must not have the attribute optimized block access!
4.2.4 ODK1500S_SQL_GetData
The block ODK1500S_SQL_GetData writes the data, which have been requested
by a previous SQL select statement, from the database to a data block. To be able
to write data to a data block, it is necessary to have successfully executed the
block ODK1500S_SQL_SetStatement by a select statement before.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 16
4 Function mechanisms
4.2 Description of the function blocks
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 17
4 Function mechanisms
4.2 Description of the function blocks
ATTENTION The SQL data types DOUBLE and REAL are 64Bit data types. The SQL
driver changes them into STEP 7 real data type with 32Bit. Due to the
change of a 64Bit value into a 32Bit value, this one loses accuracy.
Module parameter
Table 4-8: Parameter ODK1500S_SQL_GetData
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function.
InOut sqlReceivedDat VARIANT At this place, a data block with the structure for the returned
a data has to be connected.
Output DONE BOOL This output value indicates that the instruction to execute the
ODK function has been terminated successfully.
Output BUSY BOOL This output value indicates that the ODK function is still being
executed.
Output ERROR BOOL This output value indicates that an error has occurred during
the execution of the ODK function. The output value
STATUS shows further information on this matter.
Output STATUS INT This output value gives information on possible sources of
the error if an error has occurred during the execution of the
ODK function.
Siemens AG 2015 All rights reserved
Output fctError BOOL This output value indicates that an error has occurred during
the execution of an SQL driver function. The status values at
the outputs FctErCode give further information on this matter.
Output fctWarning BOOL This output value indicates that a warning message has been
shown during the execution of an SQL driver function. The
status values at the outputs FctErCode give further
information on this matter.
Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver
function
The following figure shows a data block with a possible structure for returned data.
This one can be connected to the parameter sqlReceivedData.
Figure 4-8: Data block for returned data
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 18
4 Function mechanisms
4.2 Description of the function blocks
4.2.5 ODK1500S_SQL_GetBlob
If the return values of a SELECT statement contain a BLOB value, the returned
data can be output by means of the ODK1500S_SQL_GetBlob at the parameter
sqlReceivedBlob. It is necessary to connect a data block which contains an
according Blob-PLC data type. Exception is made for the data type CHAR (S7
STRING). The data type STRING in combination with a BLOB value is not
supported. The PLC data types contained in the data block have to be present in
the same order as the data of the binary BLOP stream are made available. If the
order is not the same or if the data type is different, the values separated from the
BLOP stream will not be correct. In one BLOB stream, for example, 25 integer
values (each one with 4 byte) are transmitted. However, in the belonging data
block for the BLOB values, small integer values (each one with 2 byte) are made
available. After that, the BLOB stream is divided up into values of 2 byte each, with
the result that the separated data represent wrong values. If integer values are
used with 4 byte, the represented values are correct. At the end of each listed
Siemens AG 2015 All rights reserved
BLOB stream in the data block, the PLC data type END_OF_BLOB has to be
used.
ATTENTION At the end of each listed BLOB stream in the data block, the PLC data
type END_OF_BLOB has to be used.
The data type string is not supported in combination with the BLOB
values.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 19
4 Function mechanisms
4.2 Description of the function blocks
ATTENTION The maximum quantity of data which can be used in a complete stream
(e.g. BLOB1 and BLOB2) is limited by the maximum quantity of data
(64Kbyte) which is available in a non-optimized data block and by the
maximum number of 30000 values being available. If the stream exceeds
64Kbytes, the data will not be transmitted (BLOB values and standard
values) from the database.
Module parameter
Table 4-11: Parameter ODK1500S_SQL_GetBlob
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function.
InOut sqlReceivedBlob VARIANT At this place, a data block with the structure for the returned
data has to be connected.
Output DONE BOOL This output value indicates that the instruction to execute the
ODK function has been terminated successfully.
Output BUSY BOOL This output value indicates that the ODK function is still being
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 20
4 Function mechanisms
4.2 Description of the function blocks
The following figure shows a data block with a possible structure for a returned
BLOB stream. This one can be connected to the parameter sqlReceivedBlob.
Figure 4-10: Data block for returned BLOB data
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 21
4 Function mechanisms
4.2 Description of the function blocks
4.2.6 ODK1500S_SQL_Disconnect
Module parameter
Table 4-12: Parameter ODK1500S_SQL_Disconnect
Type Name Data type Description
Input REQ BOOL A rising edge of this input value activates the execution of the
ODK function
Output DONE BOOL This output value indicates that the instruction to execute the
ODK function has been terminated successfully
Output BUSY BOOL This output value indicates that the ODK function is still being
executed.
Output ERROR BOOL This output value indicates that an error has occurred during
the execution of the ODK function. The output value
STATUS shows further information on this matter.
Output STATUS INT This output value gives information on possible sources of
the error if an error has occurred during the execution of the
ODK function.
Output fctError BOOL This output value indicates that an error has occurred during
the execution of an SQL driver function. The status values at
the outputs FctErCode, odbcFctErCode, odbcFctNr,
sqlErCodes give further information on this matter.
Output fctWarning BOOL This output value indicates that a warning message has been
shown during the execution of an SQL driver function. The
status values at the outputs FctErCode, odbcFctErCode,
odbcFctNr, sqlErCodes give further information on this
matter.
Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver
function
Output odbcFctNr DWORD Error code of the SQL driver: Number of the called ODBC-
function where an error has occurred
Output odbcFctErCode DWORD Error code of the SQL driver: Error code of the ODBC
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 22
4 Function mechanisms
4.2 Description of the function blocks
4.2.7 ODK1500S_SQL_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 has to be unloaded before.
Module parameter
Table 4-13: Parameter ODK1500S_SQL_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
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.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 23
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
The database system Microsoft SQL 2014 Server Express is installed on the
database server. As an alternative, MSSQL 2008 R2 Server Express can be used
as well. To install the database, the file SQLEXPRWT_x64_ENU is executed.
Under the item installation a New SQL Server stand-alone installation is selected:
Figure 5-1: Installation center
Siemens AG 2015 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, V1.0, 08/2015 24
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
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, V1.0, 08/2015 25
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
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.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 26
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
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 StartProgram 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 the Port 2301 has to be entered. After that, the service hast to be started again.
Figure 5-7: TCP/IP settings
Siemens AG 2015 All rights reserved
Note The settings only become effective when the according service has been started
again.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 27
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
To restore the supplied demo database, the SQL Server Management Studio has
to be started. Then, the Windows authentication has to be selected to log in. A
password is not necessary in this case. Click the right mouse key on database to
select the option for restoration:
After the name as well as the path indication of the archived database has been
selected, the restoration can be confirmed by pushing OK. The following figure
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 28
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
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. To
generate a login, you have to open the SQL Server Management Studio and select
the Windows authentication for the login:
Figure 5-10: Login with Windows authentication
Siemens AG 2015 All rights reserved
Then, open the folder Security in the left part of the window. Click with the right
mouse key on Login -> new Login and generate a new login.
In the open window, you have to select the SQL server authentication. Then, the
login name and the password are defined. As the standard database, the restored
database is selected in the example application (DEMO_MSSQL_DATABASE):
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 29
5 Installation and commissioning
5.1 Installation and commissioning of the MSSQL demo database
Under the menu item User Mapping, please activate the following settings:
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 30
5 Installation and commissioning
5.2 Installation and commissioning of the SQL driver on the runtime PC
After the new login has been defined, you can choose between the Windows and
the SQL server authentication with the next establishment of the connection.
The installation of the SQL driver for the SQL database connection is limited to the
execution of the DLL-Install.bat file. During the installation, the DLL has to be
located in the same directory as the Install.bat file.
The ODBC driver is used to establish the connection to the SQL database.
This one has to be configured once. Doing so, you have to consider whether the
SQL server is running on a 64-Bit operating system or on a 32-Bit operating
system. We recommend executing the parameterization of the ODBC only after
having generated the SQL database.
In general, the ODBC driver is installed on the runtime PC under ControlPanel-
>System and Security->Administrative Tools->Data Sources (ODBC). Depending
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 31
5 Installation and commissioning
5.2 Installation and commissioning of the SQL driver on the runtime PC
on the configuration of the operating system of the runtime PC, the 32-Bit or 64-Bit
application is shown as a shortcut here.
To execute the correct application of the ODBC configuration, we recommend
proceeding as follows:
SQL Server runs on a 32-Bit system:
Execute Windows->system32->odbcad32.exe
SQL Server runs on a 64-Bit system:
Execute Windows->SysWOW64->odbcad32.exe
Now, you can generate a new interface under the tab System DSN:
Figure 5-13: ODBC driver configuration 1
Siemens AG 2015 All rights reserved
After having pushed the Add button, you can select a new SQL server data
source:
Figure 5-14: ODBC driver configuration 2
Now, the actual configuration follows. In the first dialog, you select the DSN name,
a description as well as the SQL server. For the demo database, the system DSN
name should be defined as follows:
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 32
5 Installation and commissioning
5.2 Installation and commissioning of the SQL driver on the runtime PC
After that, the SQL server authentication has to be selected and the login data for
the demo database have to be indicated. For this, the preset user name winacsql
and the password 1234 have to be selected:
Figure 5-16: ODBC driver configuration 4
Siemens AG 2015 All rights reserved
ATTENTION To access to the SQL database via TCP/IP, it is necessary to define a user
in the database management studio before.
Via the button Client Configuration, you have to check the settings which should
have already been set to TCP/IP before and the previously selected SQL server
should be indicated:
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 33
5 Installation and commissioning
5.2 Installation and commissioning of the SQL driver on the runtime PC
The next step can be skipped by Next and then you can finish the configuration
by pushing the button Finish:
Figure 5-18: ODBC driver configuration 6
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 34
6 Operation of the application
6.1 Use of the example application
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 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 35
6 Operation of the application
6.1 Use of the example application
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 36
6 Operation of the application
6.1 Use of the example application
Organization blocks
Main (OB1): Call of FB_SQL_CALL
Diagnostic error interrupt (OB82): Sets the request bit for the automatic loading
of the SQL driver DLL after, for example, Windows has been restarted.
Function blocks
FB_SQL_CALL: Multi instance call of the ODK1500S-SQL function blocks
ODK1500S_SQL_Load, ODK1500S_SQL_Connect,
ODK1500S_SQL_SetStatement, ODK1500S_SQL_GetData,
ODK1500S_SQL_GetBlob, ODK1500S_SQL_Disconnect,
ODK1500S_SQL_Unload: ODK1500S-SQL function blocks (see chapter 4.2)
Data blocks
FB_SQL_Call_DB: Instance of the FB_SQL_CALL
ODK1500S_Startup_DB: contains trigger bit for the automatic loading of the
SQL driver DLL
Siemens AG 2015 All rights reserved
ODBC_LOGIN_DATA: Here, the login data for the ODBC interface is indicated
SQL_ARGUMENTS: Here, the SQL arguments are indicated
SQL_STRINGS: Here, the SQL strings for the SQL statements are indicated
SQL_SELECT_DB_DATA: Here, the data of the database, which are returned
by an SQL select statement, are stored
SQL_FETCHED_BLOB_INT: Here, the Blob data of the database, which are
returned by an SQL select statement, are stored
SQL_CONROL_DB: central control and watch data block in the example
application
Watch table
ODK1500S_ControlTable: Watch table to control the example application
(contains variable from the SQL_CONTROL_DB)
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 37
6 Operation of the application
6.1 Use of the example application
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. The trigger for this is
set in OB82 and reset by the block ODK1500S_SQL_Load after the DLL has been
loaded.
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_ControlTable
Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_Load.REQ to 1
The function block ODK1500S_SQL_Load is called in the FB_SQL_Call.
Before transmitting the SQL statements to the database, you have to establish
once a connection to the database or to the SQL server.
Doing so, please proceed as follows:
Siemens AG 2015 All rights reserved
For the example application, the SQL statements being defined in the data blocks
SQL_STRINGS and SQL_ARGUMENTS are used.
Note For the correct functioning of the example application, please ensure that only
one SQL statement is selected!
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 38
6 Operation of the application
6.1 Use of the example application
A manual unloading is only necessary in case of exchanging the DLL. Doing so,
please proceed as follows:
Open the watch table ODK1500S_ControlTable
Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_Unload.REQ to 1
The function block ODK1500S_SQL_Unload is called in the FB_SQL_Call.
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.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 39
6 Operation of the application
6.2 Adaption of the example application to own requirements
For this, please enter in the data blocks ODBC_LOGIN_DATA the login data you
have defined for the connection to you database.
Note The login data have to correspond to those ones you have entered with the
parameterization of the ODBC driver. Please refer to chapter 5.2.2.
ATTENTION In STEP 7, strings are marked with '. However, SQL requires ' as well.
Thus, to be able to represent a string in SQL, you have to put before and
after the $: ('$'String$'').
In the data block SQL_ARGUMENTS you define the SQL data in the same order
as in the SQL string. Doing so, you have to use the pre-defined PLC data types for
each SQL data type.
Both data block are transmitted to the block ODK1500S_SQL_SetStatement.
If you use the SQL select statements, please adapt accordingly the order and the
structure of the data in the data block SQL_SELECTDB_DATA or
SQL_FETCHED_BLOB_INT.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 40
7 Error codes
7.1 Overview
7 Error codes
7.1 Overview
The ODK1500S-SQL driver provides different types of error codes:
ODK error codes according to ODK 1500S
Error codes of the ODK1500S-SQL driver
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 41
7 Error codes
7.2 Error Codes ODK1500S
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 42
7 Error codes
7.3 Error Codes ODK1500S SQL driver
Error Description
Code
(HEX)
ODK application 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.
Wait until the "<STEP7Prefix>_Unload" instruction has ended. Then load the ODK
application again.
Windows is not available
ODK service is not running
Start the ODK service manually or restart Windows.
Unload the ODK driver
ODK application could not be unloaded for the following reasons:
Windows is not available
ODK service is not running
Start the ODK service manually or restart Windows.
ODK application could not be (un)loaded. There is currently not enough memory available
0x80C2
at the Windows end.
ODK application could not be (un)loaded. The CPU currently does not have enough
0x80C3
memory.
Siemens AG 2015 All rights reserved
These codes describe errors of the ODK functions of the SQL driver. For example,
if a data type in a data block does not correspond to the read value of the
database.
Table 7-3: Function Error Codes
Error- Description
Code
9500 Wrong format specification in STRING for ARGUMENT
9502 Buffer Overflow in ARGUMENT read
9503 Read S7 ARGUMENT TYPE failed
9504 Read S7 ARGUMENT failed by INT
9505 Read S7 ARGUMENT failed by SMINT
9506 Read S7 ARGUMENT failed by DOUBLE
9507 Read S7 ARGUMENT failed by REAL
9508 Read S7 ARGUMENT failed by STRING
9509 Wrong S7 ARGUMENT TYPE not defined
9510 No PRINTF ARGUMENT in STRING for reserved ARGUMENT
9520 BUFFEROVERFLOW in value write
9521 READ S7 VALUETYPE failed
9522 Write S7 VALUE failed by INT
9523 Write S7 VALUE failed by SMINT
9524 Write S7 VALUE failed by DOUBLE
9525 Write S7 VALUE failed by REAL
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 43
7 Error codes
7.3 Error Codes ODK1500S SQL driver
Error- Description
Code
9526 Write S7 VALUE failed by STRING
9527 Wrong S7 VALUE TYPE not defined
9528 No S7 VALUETYPE for SQLVALUETYPE available
9529 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected INT
9530 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected SMINT
9531 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected DOUBLE
9532 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected REAL
9533 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected STRING
9555 Not defined PRINTF ARGUMENT in STRING
9559 Cant verify query the value
9561 Buffer overflow at fetched BLOB columns
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 44
7 Error codes
7.3 Error Codes ODK1500S SQL driver
These codes describe errors when using the ODBC class. The ODBC class is the
interface between SQL driver and database.
Table 7-5: ODBC Function Error Codes
Status Description
0000 ODBC FUNCTIONRET ok
8501 ODBC SQL OBJECT CALL initialization failed
8502 ODBC SQL OBJECT call execution failed
8503 ODBC SQL OBJECT call FETCH failed
8504 ODBC SQL OBJECT call CLOSE DATABASE failed
8505 ODBC FETCH ODK buffer Overflow
8506 undefined sql value type during create column type
8507 Sql unknown database column type
8508 Something wrong by sql database in character set
8509 No data existing
Siemens AG 2015 All rights reserved
These codes describe errors and notes sent by the SQL server or ODBC driver.
These codes are only read by the SQL driver.
Table 7-6: SQL Error Codes
Status Description
01000 General warning
01001 Cursor operation conflict
01002 Disconnect error
01003 NULL value eliminated in set function
01004 String data, right truncated
01006 Privilege not revoked
01007 Privilege not granted
01S00 Invalid connection string attribute
01S01 Error in row
01S02 Option value changed
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 45
7 Error codes
7.3 Error Codes ODK1500S SQL driver
Status Description
01S06 Attempt to fetch before the result set returned the first rowset
01S07 Fractional truncation
01S08 Error saving File DSN
01S09 Invalid keyword
07001 Wrong number of parameters
07002 COUNT field incorrect
07005 Prepared statement not a cursor-specification
07006 Restricted data type attribute violation
07009 Invalid descriptor index
07S01 Invalid use of default parameter
08001 Client unable to establish connection
08002 Connection name in use
08003 Connection does not exist
08004 Server rejected the connection
08007 Connection failure during transaction
08S01 Communication link failure
21S01 Insert value list does not match column list
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 46
7 Error codes
7.3 Error Codes ODK1500S SQL driver
Status Description
42000 Syntax error or access violation
42S01 Base table or view already exists
42S02 Base table or view not found
42S11 Index already exists
42S12 Index not found
42S21 Column already exists
42S22 Column not found
44000 WITH CHECK OPTION violation
HY000 General error
HY001 Memory allocation error
HY003 Invalid application buffer type
HY004 Invalid SQL data type
HY007 Associated statement is not prepared
HY008 Operation canceled
HY009 Invalid use of null pointer
HY010 Function sequence error
HY011 Attribute cannot be set now
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 47
7 Error codes
7.3 Error Codes ODK1500S SQL driver
Status Description
HY109 Invalid cursor position
HY110 Invalid driver completion
HY111 Invalid bookmark value
HYC00 Optional feature not implemented
HYT00 Timeout expired
HYT01 Connection timeout expired
IM001 Driver does not support this function
IM002 Data source name not found and no default driver specified
IM003 Specified driver could not be loaded
IM004 Drivers SQLAllocHandle on SQL_HANDLE_ENV failed
IM005 Drivers SQLAllocHandle on SQL_HANDLE_DBC failed
IM006 Drivers SQLSetConnectAttr failed
IM007 No data source or driver specified; dialog prohibited
IM008 Dialog failed
IM009 Unable to load translation DLL
IM010 Data source name too long
IM011 Driver name too long
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 48
8 Commissioning Tool SQLViewer
8.1
User interface
The upper area of the user interface of the tool shows the status of the connection
to the SQL driver. If the tool detects an S7-1500 software controller with a loaded
SQL driver and activated commissioning mode, this is indicated in the field
Viewer.
The middle area shows the textual output of the read messages.
In the lower area, you can find two buttons. With the Clear button, you can clear
the view provided that there is no connection to the controller. The Save Log
button permits to save the current content of the text field as TXT file.
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 49
8 Commissioning Tool SQLViewer
8.1
Operation
The tool has to be run on the same PC as the S7-1500 software controller.
To start the tool, just double-click on SQLViewer.exe.
The moment of time when the tool is started is unimportant.
To be able to use the tool, the SQL driver must be set to commissioning
modes which can be activated by establishing a connection to the SQL
database (ODK1500S_SQL_Connect) with set enableDebug. If you want to
deactivate the commissioning mode again, just disconnect the connection
(ODK1500S_SQL_Disconnect).
After having started, no further operation is necessary. The tool connects itself
automatically when there is a running S7-1500 software controller with loaded SQL
driver and activated commissioning mode on the same PC. Then, the tool
immediately indicates all logged messages.
Mode of functioning
The messages are read via a shared memory. The SQL driver writes the
messages to this memory and the tool can read this at any time. The size of this
memory area is limited. If this size is exceeded, the memory will be cleared again
(ring buffer). In this case, the indicated text in the SQL viewer will disappear as
well.
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 50
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
10 History
Table 10-1
Version Date Modifications
V1.0 08/2015 First version
Siemens AG 2015 All rights reserved
ODK 1500S-SQL-driver
Entry-ID: 109479140, V1.0, 08/2015 51