WinCC Flexible SQL Database Archive en
WinCC Flexible SQL Database Archive en
Question
This entry originates from the Service&Support Portal of Siemens AG, Sector
Industry, Industry Automation and Drive Technologies. The conditions of use
specified there apply (www.siemens.com/nutzungsbedingungen).
Go to the following link to download this document.
http://support.automation.siemens.com/WW/view/de/44240726
Question
How can you output tags from an SQL database via a trend archive?
Answer
Follow the instructions and notes listed in this document for a detailed answer to
the above question.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
Contents
Contents
1
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
1 Configuration Notes
Configuration Notes
This entry includes the principal configuration steps for...
Reading out the archived tags via a trend display. Here you can preset the
period of time in a selection window.
The archive names in this database are composed of the elements below:
The figure below shows an example of how the archived entries are displayed.
Figure 1-1
Database name
Archivename + Year + Month
Archive entries
Archivename + Year + Month + Day + Time
Additional entries
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
1 Configuration Notes
Note
When "MS SQL Server" is mentioned in the documentation, this always refers to
the "Microsoft SQL Server 2005 Express Edition".
When "Microsoft SQL Management Studio" is mentioned in the documentation,
this always refers to the "Microsoft SQL Server Management Studio Express".
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
SQL Database
Information on how to operate the SQL database is given below.
2.1
Table 2-1
No.
1.
Description
Picture
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
No.
2.
Description
Picture
(1)
The instance name in this example is
"WINCCFLEXEXPRESS".
You can specify the server name and
instance name "manually" or via the dropdown list (1).
Select the
"Local Servers" menu command.
Select your local server and confirm
the input with "OK".
(2)
Authentication
Select the authentication here.
In this case
"Windows Authentication".
After specifying the server name and
authentication, click on the "Connect"
button.
The connection to the server is set up.
3.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
No.
4.
Description
Start the SQL server
If the server has not already been started,
indicated by the "red" icon (1), then start
the server manually.
5.
Picture
(1)
(2)
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
2.2
PC with
MS SQL database
(central PC)
WinCC flexible
RT station 01
Remote
access
WinCC flexible
RT station 02
The default setting of the "Microsoft SQL Server 2005 Express Edition" does not
permit "Remote Access".
Below are the settings to be made to enable "Remote Access".
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
2.2.1
Table 2-2
No.
1.
Description
Picture
2.
3.
10
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
No.
4.
Description
Picture
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
11
2 SQL Database
2.2.2
Table 2-3
No.
1.
Description
Picture
2.
3.
12
(1)
(2)
(3)
(4)
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
No.
4.
Description
Picture
(1)
(2)
(3)
(4)
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
13
2 SQL Database
2.3
Table 2-4
No.
1.
Description
Picture
2.
3.
14
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
No.
4.
Description
Picture
(3)
(1)
(2)
Login settings
Select a login option for the SQL data
source. If you are in a domain, you can
then use your domain account.
In this example, we have taken the
options selected in the picture.
Then click on the "Next>" button.
Note:
When you click on the "Next" button, the
system attempts to set up a connection to
the SQL server. If this does not succeed,
you get an error message (see next
point).
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
15
2 SQL Database
No.
6.
Description
Picture
7.
8.
(1)
16
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
2 SQL Database
No.
9.
Description
Picture
10.
(1)
(2)
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
17
3 WinCC flexible ES
WinCC flexible ES
This chapter describes how to configure and make various settings for logging data
in an SQL database.
Details are given in the attached project.
Note
3.1
All the settings already described have been made in the attached configuration.
Table 3-1
No.
1.
Description
Create a tag log
First create two new logs.
In this example:
Data_Logs
Data_Logs_Trend_View
Settings:
General
Open the properties of the tag log
"Data Logs > General".
2.
Picture
(1)
(2)
Define properties
Properties
Open the properties of the tag log
"Properties > Properties".
You can make the settings individually.
Detailed information on the separate
points is available in the Online Help of
WinCC flexible.
18
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
3 WinCC flexible ES
No.
3.
Description
Picture
3.2
Tag Logging
Description
Picture
Logging
Open the properties of the tags
"Properties > Properties > Logging".
Trigger (2)
Here you enter the acquisition mode.
In this case "Cyclic continuous".
You do not need to make any other
settings for logging.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
(1)
(2)
19
3 WinCC flexible ES
3.3
Scripts
3.3.1
In this example three values are logged every second. After just a short time the
table becomes very "long" and it is difficult to pick out a specific value for a specific
time.
Using the scripts you can split the existing table into several "small" tables. In this
example a database is created for each month. A separate log is created for every
hour in this database.
The name of the archive is created automatically.
Furthermore, you can use the scripts and a text list to predefine a specific period of
time and select a specific log. The values from the log chosen can then be
displayed via a trend archive.
20
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
3 WinCC flexible ES
3.3.2
Scripts used
This chapter provides you with information on the scripts configured.
Note
A certain amount of experience and basic knowledge of the SQL instruction set
is required for creating these scripts.
Refer here to Entry ID: 26283062.
Line 5:
Declaration of tags
Line 9:
Line 10:
Line 14:
The description of the scripts below limits itself to the function that scripts execute.
Please refer to the configuration for details.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
21
3 WinCC flexible ES
S1_Create_Database_Table
The script is executed once when WinCC flexible Runtime starts.
The script creates a new database for the current month in an SQL database.
If a database already exists for the current month, a system message is issued.
The database name is composed of the elements below:
S2_Archive_Data_Hourly
The script is call once at the beginning of each hour via the scheduler.
The script copies all the values of the "previous" hour from the "Data_Logs" archive
and inserts the data into a newly created archive.
The name of the new archive is composed of the elements below:
Functional sequence:
1. When the WinCC flexible Runtime starts, the "Data_Logs" archive (Link) is
created in the system database of the SQL server. The configured values are
stored continuously in this archive.
2. At the beginning of each hour the script "S2_Archive_Data_Hourly" is called via
the "Scheduler".
The script creates a new archive for the past hour.
Then all the values of the past hour between the minute "xx:00:00" and the
minute "xx:59:59" are copied from the "Data_Logs" archive and pasted into the
newly created archive.
3. After copying, the "old" values are deleted in the "Data_Logs" archive.
4. Example:
Archiving is started at 14:35:42. At 15:00 the scheduler executes the script.
All the values between 14:35:42 and 14:59:59 are stored in the archive named
"Data_Logs_2010_7_28_14".
(Archive name + year + month + day + hour)
Continuous archiving of the subsequent data in the "Data_Logs" archive is not
interrupted during the copying procedure.
22
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
3 WinCC flexible ES
S3_Load_Database_Table
The script is called via the "Download archive data" button.
The script copies the data logged in the given time and pastes it into the
"Data_Logs_Trend_View" archive.
These values from the "Data_Logs_Trend_View" are displayed via a trend display.
If the archive selected is not available, a system message is issued.
Functional sequence:
1. When the WinCC flexible Runtime starts, the "Data_Logs_Trend_View" archive
(Link) is created in the system database of the SQL server. The archive acts as
a "temporary" buffer for values.
2. The "S2_Archive_Data_Hourly" script creates a new archive with the
corresponding values every hour.
3. You select a file archived in the SQL database by entering a specific point in
time (date and time) via text lists.
4. After specifying the time period you press the "Download archive data" button
to execute the script.
Based on time period specified the script searches the archived file in the SQL
database and copies the contents into the "Data_Logs_Trend_View" archive.
The values from the "Data_Logs_Trend_View" archive can then be displayed via a
trend archive.
S4_Export_Archiv_As_CSV_File
You call the script via the "Export selected archive as CSV file" button.
The script copies the data archived in the SQL database from the specified period
of time and creates a *.CSV file on the C:\ drive.
The name of the new file is composed of the elements below:
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
23
4.1
Data has been logged in the SQL database via WinCC flexible Runtime.
Description
Picture
Data_Logs_Trend_View0
Data_Logs0
(1)
(2)
Table View
The figure below shows you an opened
table..
In this case it is the data from the table
"Data_Logs_2010_7_29_17".
You can add new values to the table and
change existing values.
If you make changes to the table, you
must then save the data.
24
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
No.
3.
Description
Picture
4.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
25
4.2
Table 4-2
No.
1.
Description
Picture
Screen 01:
"Trend View"
The trend display is for the graphical
representation of tag values from the
current process.
The values of the tags below are displayed.
HMI_Archive_Data.Tag_01
HMI_Archive_Data.Tag_02
HMI_Archive_Data.Tag_03
Screen 02:
"Archive Trend View"
Via this screen you can call the archived
values from the SQL database.
Furthermore, you can export the data from
the selected archive into a CSV file.
3.
Screen 03:
"System Site"
Via this screen you can change the
language (Deutsch/English) and end
Runtime.
Alarm events are output via the alarm
display.
26
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
Picture
(1)
You press the "Trend View" button to call the "Trend View" screen.
The Trend View shows the current process values of three tags.
Using the Trend View buttons (1) you can execute the functions shown.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
27
Description
2.
Picture
(4)
(1)
(2)
(3)
You press the "Archive View" button to call the "Archive Trend View" screen.
Via this screen you can graphically output the archived values from the SQL database.
Notes:
- If there is no archive available in the SQL database for the date selected, you get a
system message.
- If no values are displayed in the trend view, navigate to the left and right with the
buttons of the trend view (4). The archived values might not be in the time range
currently displayed.
You can export the archived data from the SQL database into a CSV file.
Notes:
- If there are no values available in the SQL database for the date selected, you get a
system message.
Sample view see link.
28
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
Description
3.
Picture
You press the "System Site" button to call the "System Site" screen.
On this screen you can make the settings below.
Via the "Deutsch" (English) button you can select the language of the Runtime user
interface.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
29
Description
4.
Picture
4-1
The names of the archive files are composed of the elements below:
"Archive name_year_month_day_time"
30
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
4.2.1
Table 4-4
No.
1.
Description
Picture
2.
3.
4.
Import data
Select the menu command
"Data > Import External data >
Import Data".
A window opens in which you can
navigate to the desired CSV file.
Select the desired CSV file and click on
the "Open" button.
The "Text Import Wizard" opens.
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
31
No.
5.
Description
Picture
6.
7.
32
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
No.
8.
Description
Picture
Import data
Now you specify whether the data to
be imported is to be added to an
existing worksheet or a new worksheet.
In this example:
"Existing worksheet"
Then click the "OK" button.
9.
10.
Format cells
In the dialog box you select the
"Number > Custom" menu.
Enter the format below in the input field
(1).
"DD.MM.YYYY hh:mm:ss"
(pay attention to character cases!)
(1)
SQL Datenbankzugriff
V1.0, Entry ID: 44240726
33
4.2.2
Troubleshooting
If no data is logged in the SQL database, run through the points listed below.
Check IP address
If the SQL server and WinCC flexible Runtime are installed on different computers
(Remote Access), then check the IP addresses used on the PCs. The IP
addresses must be in the same IP band and subnetwork. If necessary, get in touch
with your system administrator.
SQL server address
Check the SQL server address used (link).
Data source name
Check the data source name used. The name is used for parameterizing the logs
and in the scripts (link).
Start the SQL server
Make sure that the SQL server has been started (link).
WinCC flexible Runtime
Make sure that the SQL server is started before starting the WinCC flexible
Runtime and that the connection to the SQL server is not interrupted during
operation.
Sample error messages
Figure 4-2
34
SQL Datenbankzugriff
V1.0, Entry ID: 44240726