1. Problem Definition and Scope
WinCC V7.0 and later releases store process tags in volatile runtime memory by default. When the WinCC Runtime is shut down — whether by an operator action, a controlled stop, or an unplanned power loss — every internal counter, totalizer, and process value that is not explicitly persisted is reset to its start value (typically 0) when the runtime is restarted.
This behavior breaks any application that depends on accumulated counters (parts produced, runtime hours, energy totals, fault counts). The objective of this reference is to document the supported and field-proven methods for capturing the last value of a tag before a shutdown and re-injecting it into the runtime after a restart.
The following approaches are covered:
- Runtime Persistency (built-in, available from WinCC V7.0 SP3 / V7.2 onward)
- Querying the persisted values table via WinCC OLEDB Provider or directly through SQL
- Tag Logging archive with the "Also put archived value in a tag" option
- External CSV / XLS / MDB file as a fallback buffer
- Dynamic start-value assignment through VBScript on tag value change
2. Prerequisites
| Item | Requirement |
|---|---|
| WinCC Version | V7.0 SP3 minimum for Runtime Persistency; V7.0 base for Tag Logging + OLEDB |
| SQL Server | SQL Server 2008 R2 / 2012 / 2014 / 2016 / 2019 (RT-DSN instance installed by WinCC setup) |
| Editor | WinCC Explorer → Tag Management, Tag Logging, Graphics Designer |
| Scripting | VBScript editor (C script optional, not required for persistence) |
| Permissions | Local administrator on the WinCC station for SQL queries against RT-DSN |
3. Method 1 — Runtime Persistency (Recommended)
Runtime Persistency is the simplest built-in mechanism. WinCC writes the current value of every flagged tag to a dedicated SQL table just before the runtime terminates and re-loads it on the next start.
3.1 Configuration in Tag Management
- Open WinCC Explorer → Tag Management.
- Right-click the target tag (e.g.
MyCounter) and select Properties. - Activate the option Runtime Persistency (German: Runtime-Persistenz).
- Repeat for every tag that must survive a restart.
- Activate the WinCC project so the change is written to the RT-DSN configuration.
On shutdown, WinCC performs an internal UPDATE against the SQL table PERSTAGRTLIST in the RT-DSN database. The last value of every persisted tag is stored there keyed by tag name.
3.2 Reading the Persisted Value Manually
Open SQL Server Management Studio, connect to WINCC<ServerName>\WINCC, and execute:
USE RT-DSN;
GO
SELECT TAGNAME, VALUE, TIMESTAMP
FROM dbo.PERSTAGRTLIST
WHERE TAGNAME = 'MyCounter';
GO
The VALUE column holds the value as a VARBINARY blob, the same representation used throughout WinCC's internal tables. Cast it to the appropriate type for inspection:
SELECT TAGNAME,
CAST(VALUE AS VARCHAR(64)) AS ValueAsText,
TIMESTAMP
FROM dbo.PERSTAGRTLIST
WHERE TAGNAME = 'MyCounter';
If the runtime has not yet been started, the row may not exist; the table is populated on the first clean shutdown of a project that has Runtime Persistency active.
3.3 Known Issue — Global Action Re-trigger on Persisted Reload
Two reliable workarounds exist:
3.3.1 Timer-based guard
Create a non-persisted auxiliary tag (e.g. Tag_Time) that is incremented every second by a Global Script. In every action that depends on persisted tags, gate execution on a condition such as:
If HMIRuntime.Tags("Tag_Time").Read > 120 Then
' > 2 minutes of runtime elapsed - safe to act on persisted value
HMIRuntime.Tags("ProcessCounter").Write _
HMIRuntime.Tags("MyCounter").Read
End If
Because Tag_Time is not persisted, it always starts at 0 on restart, giving every script a clean, deterministic window during which persisted tags finish re-loading.
3.3.2 Conditional check on the persisted value
For tags where the persisted value can only be a positive integer (e.g. part counters), block the action while the value equals the tag's start value:
Dim v
v = HMIRuntime.Tags("MyCounter").Read
If v > 0 Then
' persisted value is now in place
DoMyAction()
End If
4. Method 2 — WinCC OLEDB Provider Query
When Runtime Persistency is not available (WinCC V7.0 base) or when a specific historic value is required (for example, the value at the moment of the last archive cycle), use the WinCC OLEDB Provider. It is a read-only provider shipped with every WinCC installation under WinCCOLEDBProvider.1.
4.1 Connection String
Provider=WinCCOLEDBProvider.1;
Catalog=CC_OpenArchive_<YYYY_MM_DD_hh_mm_ss>_<Server>;
Data Source=<ServerName>\WINCC;
The Catalog parameter selects the open runtime database of the active project. In a running runtime it is the value of @DatasourceNameRT from the project properties; in a closed project, the catalog must match the segment that was archived.
4.2 Querying the Last Value of an Archived Tag
The query form TAG:R returns the value of a tag over a time window. The following call returns the last interpolated value of YOURTAG in the archive group ArTags:
SELECT * FROM
(
SELECT TOP 1 *
FROM OPENQUERY(WinCCOLEDB,
'TAG:R,''ArTags\YOURTAG'',''0000-00-00 00:00:00.000'',''0000-00-00 00:00:00.000'',''TIMESTEP=60,258''')
) AS LastValue
The trailing pair in the function call carries the control parameters:
| Parameter | Value | Meaning |
|---|---|---|
| TIMESTEP | 60 | Step size in seconds for the time axis of the returned series |
| Aggregation | 258 | Code 258 = interpolation (last known value held forward) — returns the most recent archived value |
Other relevant aggregation codes (decimal interpretation per WinCC Information System — "Configuration of the Tag Logging"):
| Code | Method | Use case |
|---|---|---|
| 1 | Average (time-weighted) | Continuous values (temperature, level) |
| 2 | Minimum | Low-water mark, lowest pressure |
| 3 | Maximum | Peak load, peak temperature |
| 4 | Sum | Energy totals, flow totals |
| 5 | Count of values | Number of changes in the window |
| 258 | Last value (interpolated) | Snapshot of the last known value at query time |
| 259 | First value (interpolated) | Value at the beginning of the window |
The result row contains columns TimeStamp, RealValue (for float tags), DWORDValue / LongValue (for integer / counter tags), Quality and Flags. Use the column that matches the tag's configured data type.
4.3 Driving the Query from a VBScript Action
A cyclic Global Action can call the OLEDB query and write the returned last value back into an internal tag, effectively rebuilding the persistence behaviour on platforms where the built-in flag is missing:
Dim sCon, oConn, oRS, sTag
sCon = "Provider=WinCCOLEDBProvider.1;Catalog=" & _
HMIRuntime.Tags("@DatasourceNameRT").Read & _
";Data Source=" & HMIRuntime.Tags("@DatasourceNameRT").Read & _
";Mode=Read;"
Set oConn = CreateObject("ADODB.Connection")
oConn.Open sCon
sTag = "ArTags\YOURTAG"
Set oRS = oConn.Execute("TAG:R,'" & sTag & _
"','0000-00-00 00:00:00.000','0000-00-00 00:00:00.000','TIMESTEP=60,258'")
If Not oRS.EOF Then
HMIRuntime.Tags("ProcessCounter").Write oRS.Fields("DWORDValue").Value
End If
oRS.Close
oConn.Close
Set oRS = Nothing
Set oConn = Nothing
5. Method 3 — Tag Logging "Also Put Archived Value in a Tag"
WinCC Tag Logging has a built-in feature that re-injects the most recent archived value of a process tag back into a process tag of the same type. This is the cleanest option when the counter is already being archived.
5.1 Configuration Steps
- Open Tag Logging editor in WinCC Explorer.
- Select the analog or counter archive tag (e.g.
MyCounter). - On the Properties dialog, activate the option "Also put archived value in a tag" (German: Auch Archivwert in Tag schreiben).
- Pick the destination process tag (typically the same tag) and the desired time range behaviour.
- Confirm with OK and re-activate the project.
On runtime start, Tag Logging replays the last archived value of the tag into the configured destination tag, eliminating the need for any custom script. This is documented in the WinCC Information System under "How to create an analog archived tag".
6. Method 4 — External File Buffer (CSV / XLS / MDB)
When neither Runtime Persistency nor Tag Logging is acceptable — for example in a multi-project station that must not write to the RT-DSN, or when the WinCC version is below V7.0 SP3 — an external file can serve as a manual persistence layer.
6.1 Pattern
- On every value change of the source tag, write the new value to a named cell or row in the external file.
- On the opening of the base picture (or on a one-shot timer after runtime start), read the saved value and write it back into the process tag.
6.2 VBScript Example (CSV)
Dim fso, ts, line
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\WinCC_Persist\MyCounter.csv", 1, False)
If Not ts.AtEndOfStream Then
line = ts.ReadLine
HMIRuntime.Tags("MyCounter").Write CLng(line)
End If
ts.Close
Set ts = Nothing
Set fso = Nothing
6.3 VBScript Example (XLS, using Excel)
Dim xlApp, xlBook, xlSheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\WinCC_Persist\Counters.xls")
Set xlSheet = xlBook.Sheets("Counters")
' Column B, row 4 is the named cell "ProcessCounter"
HMIRuntime.Tags("MyCounter").Write xlSheet.Range("ProcessCounter").Value
xlBook.Close False
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
7. Method 5 — Dynamic Start Value via VBScript
For counter tags whose start value can be reassigned at runtime, the simplest pattern is to mirror the current value into the tag's start-value slot every time it changes.
7.1 Logic
- On the Value change event of the counter tag, fire a global script.
- Read the new value and assign it to a non-persisted companion tag that holds the latest snapshot.
- On runtime start, copy the companion tag's value into the actual counter.
' Global action - triggered on value change of MyCounter
Sub OnValueChange(sTagName)
If sTagName = "MyCounter" Then
Dim v
v = HMIRuntime.Tags("MyCounter").Read
HMIRuntime.Tags("MyCounter_Snapshot").Write v
' Persist snapshot externally (see Method 4) for full restart safety
End If
End Sub
Note that VBS in WinCC Runtime cannot modify the tag's static start value stored in the configuration database — only its current runtime value. The companion-tag pattern is the standard way to bridge that limitation.
8. Troubleshooting Matrix
| Symptom | Likely cause | Diagnostic step | Fix |
|---|---|---|---|
| Tag resets to 0 after restart | Runtime Persistency not enabled | Inspect Tag Management → Properties for the tag | Enable Runtime Persistency and re-activate project |
| PERSTAGRTLIST row missing | Project never performed a clean shutdown | Check Windows Event Log for abnormal termination | Always exit WinCC Runtime cleanly; verify RT-DSN write permissions |
| Global Action executes at startup with wrong value | Persisted tag triggers Value-Change event on reload | Add tracing to the action; observe fire time | Gate the action with a 2-minute timer (Section 3.3.1) |
| OLEDB query returns empty result set | Wrong Catalog name or segment closed | Query SELECT * FROM ALGTREE to list available archives |
Use the Catalog of the open runtime segment, not a closed one |
| Code 258 returns older value than expected | Interpolation fills forward from the last logged change | Inspect archive cycle of the tag | Reduce the archive cycle to match the required resolution |
| CSV write fails on shutdown | Runtime terminated before script completed | Wrap persistence script in OnError Resume Next and log failures | Trigger the save on every value change, not only on shutdown |
| Excel object cannot be created | Excel not installed on WinCC station | Check DCOM config and registry | Replace XLS with CSV or use a database through OLEDB |
| Counter "jumps" on first cycle after restart | Start value 0 + tag was used in arithmetic | Inspect derived tag expressions | Add an enable flag that is set only after persistence reload |
9. Reference: TIA Portal / WinCC Professional Equivalent
If the project is migrated to TIA Portal / WinCC Professional (RT Professional), persistence is achieved through Data Logs and the tag-level Logging tags configuration. The same architectural idea — write the value to a non-volatile store on every change and re-load it on runtime start — applies. The configuration entry point is the Logging tags editor in the HMI tags table.
See the official Siemens documentation for TIA Portal V20:
Configuring logging tags (RT Professional) – TIA Portal V20 documentation
10. Verification Procedure
- Configure the chosen method (Runtime Persistency flag, OLEDB query, Tag Logging option, or external file) on the test tag.
- Drive the tag to a known non-zero value, e.g.
MyCounter = 1234. - Close WinCC Runtime using File → Exit (clean shutdown, not
End Process). - Query
RT-DSN.dbo.PERSTAGRTLIST(Method 1), the file (Method 4), or the archive (Method 2/3) to confirm the value was captured. - Re-start WinCC Runtime and observe the tag in Graphics Designer or in the tag table.
- Confirm the tag reads
1234immediately after the runtime is fully loaded. - If a Global Action is associated with the tag, verify that it does not fire in the first 2 minutes of runtime, or is correctly gated by the persistence-ready condition.
11. FAQ
Does Runtime Persistency exist in WinCC V7.0 base, or only in SP3?
Runtime Persistency for the Tag Management was introduced with WinCC V7.0 SP3 / V7.2 and is present in all later versions (V7.3, V7.4, V7.5). On a V7.0 base installation without SP3, use the OLEDB query (Method 2) or the external file (Method 4) instead.
Why does my Global Action execute with the wrong value right after WinCC starts?
This is a known side effect of Runtime Persistency: when WinCC re-loads the persisted value, it fires a Value-Change event on the tag, which triggers any Global Action bound to that event before the runtime is fully initialised. Add a 2-minute timer guard using a non-persisted tag, or condition the action on the persisted value being non-zero.
What does the value 258 mean in the TAG:R WinCC OLEDB query?
The trailing parameter pair 'TIMESTEP=60,258' specifies a 60-second step and aggregation code 258, which corresponds to the last interpolated value of the tag. The result is the most recent archived value held forward to the query timestamp. Use 1 for time-weighted average, 4 for sum, 2 for minimum, 3 for maximum.
Can VBScript change the static start value of a WinCC tag?
No. VBS in WinCC Runtime can only modify the current runtime value of a tag, not the start value stored in the configuration database. To achieve "last value = next start value" semantics, use a non-persisted companion tag as a snapshot, or rely on Runtime Persistency / Tag Logging "Also put archived value in a tag".
Is Microsoft Excel required on the WinCC station for the external-file method?
Not if you use CSV. The XLS / XLSX example requires a licensed and installed Microsoft Excel, which is not recommended on production WinCC stations. For production environments, prefer CSV, the WinCC User Archive, or a real database connected through OLEDB / ODBC.