Error message here!

Hide Error message here!


Error message here!


Hide Error message here!


Error message here!



[Preview: modular industrial PC (class starts at 10 a.m.)] text: WinCC realizes the interaction with database and the implementation of report

Sword finger industrial control 2021-11-25 20:33:05 阅读数:2 评论数:0 点赞数:0 收藏数:0


Industrial control technology sharing platform

It is often used by friends to write some useful data separately to relational databases, such as :SQL Server ,MySQL etc. , Then make a report to display the data , And for reports , What I usually use at present is SQL Server Bring your own free SSRS To make a report , Users can access it in the form of web pages , Pages can be exported as PDF,WORD, Or you can choose to print , Very convenient .

So for WINCC You must be very familiar with the software ,

that , How to write real-time data to WINCC Built in relational database SQL Server, And read .

step :

1) stay SQL SERVER Create a database

Log in to SQL Server, The default login method is Windows Account , Instead of a hybrid account sa( Pictured 2), The first thing you need to do is SQL Server Build a database in , If the name is “DBTEST”, Then create a table , Such as value, Enter fields in the table , And set the data format , If the field name is press,temp, Their corresponding data types are float , The field name here needs to be the same as WINCC The names of variables in are consistent ,( Pictured 1)

chart 1

chart 2

If you don't understand databases , Then you can watch this column to learn , Master database related knowledge , And the making method of the report .

2)wincc Data is written to the database

You can use buttons to write data to , At the button VBS Enter the code in the script ; Generally, we often use global scripts , Cycle triggers writing data to ( Must be in the computer properties — Check... In the startup tab " Global script running system ")

The code is as follows ( The button is the same as the global script ):

' Defining variables

Dim sCon

Dim sSql

Dim oRs

Dim conn

Dim oCom

Dim Con

Dim Data1, Data2

' The data to be written from WINCC Read into variable in , Here press and temp It must be consistent with the established fields in the database



' Database connection ,"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial ‘Catalog=DBTEST;Data Source=.\WINCC" in Initial Catalog=DBTEST You need to change the name of the actual database ,Data Source=.\WINCC It needs to be modified to data source , The full name should be when logging into the database Server name: luoyh\WINCC

Con="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBTEST;Data Source=.\WINCC"

Set conn = CreateObject("ADODB.Connection")

conn.ConnectionString = Con

conn.CursorLocation = 2


' Insert real-time data into the database ,"insert into value VALUES(" & Data1 & "," & Data2&");" here value Is the name of the table ," & Data1 & "," & Data2&" When the data here is a string, you need to use single quotation marks , Such as :' " & Data1 & " ',' " & Data2&" '

sSql="insert into value VALUES(" & Data1 & "," & Data2&");"

Set oRs = CreateObject("ADODB.Recordset")

Set oCom = CreateObject("ADODB.Command")

Set oCom.ActiveConnection = conn

oCom.CommandType = 1

oCom.CommandText = sSql

Set oRs = oCom.Execute

Set oRs = Nothing


Set conn = Nothing

The above code can write the real-time read data to the relational database , The write frequency mainly depends on the setting of cycle trigger in the global script .

3) adopt SSRS Developing reports , Display and analyze data .

adopt SSRS Data can be displayed in the form of a table , The trend curve can be generated for the data , The pie chart , The dashboard , Map and other elements , Through a certain script , You can also filter the data . You can also access the report as a web page , For many configuration software, it has Web Control , Then you can use this web Control to embed the web page into your screen to view the report . This method is very convenient , It is more powerful than the report provided by the configuration software .

SSRS Simple report developed

Various Chart

Various dashboards

The above is about WINCC In the data interaction with the database , And how to use it SSRS This concludes the introduction to realizing powerful report functions .


The posture has been set

Just wait for you to order

Author's brief introduction

Sword control Lao Luo

have 10 In the field of industrial automation SCADA,DCS,PLC And other project implementation experience , Familiar with petrochemical industry , Oilfield digitization industry , Familiar with multiple brands PLC,HMI,SCADA, Database etc. .

This article is from WeChat official account. - Sword finger industrial control (JZGKCHINA) , author : Sword control Lao Luo

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the Delete .

Original publication time : 2020-02-18

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

Copyright statement
In this paper,the author:[Sword finger industrial control],Reprint please bring the original link, thank you