Linking WinCC Archive Segments: TagLogging and Alarm Log Methods

David Krause14 min read
SiemensTutorial / How-toWinCC
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Linking WinCC Archive Segments: TagLogging and Alarm Log Methods

WinCC runtime databases are rotated by the TagLogging Fast, TagLogging Slow, and Alarm Logging (Message Archive) backends. When the operator copies the active project folder to a monthly backup drive, the historical segments (each consisting of a .mdf primary file and a .ldf transaction log file) become inaccessible to the live runtime because the active project no longer references them. To query trend data from those backed-up segments inside a fresh runtime instance, the segments must be re-attached to the live archive configuration. This article consolidates the manual, scripted, and connector-based procedures for attaching .mdf/.ldf archive pairs, with the C-Script batch method, the WinCC Archive Connector tool, and the parameter set that controls archive performance.

Scope: The procedures apply to WinCC V7.0 SP3 and later through WinCC V8.0 Information System. The WinCC Archive Connector applies to WinCC Unified / TIA Portal V20 RT Professional. Verify your installed version in the WinCC Explorer under Help > About before scripting.

1. WinCC Archive Architecture Overview

WinCC splits the process value archive into two configurable backends:

  • TagLogging Fast – Acquisition cycle typically 500 ms to 1 s. Used for high-speed, short-retention tags (motor currents, valve positions, analog measurements).
  • TagLogging Slow – Acquisition cycle typically 1 s to 1 h. Used for shift totals, energy counters, KPI roll-ups.

Alarm Logging maintains a single Message Archive database that stores every acknowledged, unacknowledged, and historical alarm with state transitions, comments, and operator names.

Each backend rotates its storage into discrete segments based on the configured segment size, segment time, or both. A segment is physically a Microsoft SQL Server database in the legacy MDF/LDF format (WinCC V7) or a SQL Server native database (WinCC V7.4+). When a segment is closed, the active database pointer advances to a new file, and the closed segment becomes read-only. The closed .mdf plus its .ldf must stay in the project folder or in a referenced location for OnlineTrendControl, OnlineTableControl, and AlarmControl to be able to query historical data.

Refer to the Siemens WinCC V8.0 Information System – Basics of Process Values Archiving for the canonical description of the process value archive data flow, segment rotation, and storage paths.

2. Prerequisites and Preconditions

Before attaching archived segments, confirm the following:

  1. Matching WinCC version. Archive segments created on WinCC V7.x can be opened on the same major version with the same or higher service pack. A V7.0 segment cannot be opened on a V6.2 runtime because the internal database schema differs.
  2. SQL Server consistency. Both the .mdf and the matching .ldf must be present in the same folder. A missing transaction log forces SQL Server to attempt recovery, which fails on a read-only file copied from backup.
  3. Archive Manager is closed. The TagLogging editor and Alarm Logging editor must not have a write lock on the active archive. In practice, open the WinCC Explorer before opening TagLogging to avoid contention.
  4. Runtime state. Manual linking via the right-click menu can be executed while Runtime is active. C-Script batch moves require the target folder to be writable by the WinCC runtime service account (typically CCAdmin or the local SYSTEM account when started as a service).
  5. File system rights. The CommonArchiving folder inside the project directory must inherit write permission for the user that runs the WinCC Runtime. A denied write on the destination folder results in a silent move failure that masquerades as a missing trend.
  6. Segment count limit. The WinCC archive configuration supports linking multiple segments; the practical ceiling is dictated by SQL Server Express edition limits (10 GB total database size for the bundled instance) rather than a hard WinCC count.

3. Step-by-Step: Manual Archive Linking for TagLogging

The standard way to attach a previously rotated segment is the WinCC Explorer Link Archive command.

  1. Open WinCC Explorer on the engineering station or the runtime station.
  2. In the navigation tree, expand Tag Logging.
  3. Expand the Archive Configuration node.
  4. Right-click TagLogging Fast (or TagLogging Slow) and choose Link archive... from the context menu.
  5. In the file dialog, browse to the folder that holds the backup segment (for example, D:\Backups\2024-09\CommonArchiving\).
  6. Select the .mdf file that matches the segment you want to attach and confirm with Open.
  7. WinCC will register the segment in the active archive configuration. The Trend and Table controls gain immediate access; no Runtime restart is required.
  8. To verify the segment is now visible, open the Tag Logging editor, select the linked archive, and inspect the Time range property — it should show the start and end timestamp of the imported segment.
Disconnect: The same right-click menu exposes Disconnect from archive if you need to remove a linked segment without deleting the underlying file. Always disconnect before physically deleting the .mdf to avoid leaving dangling handles in the WinCC configuration file <Project>.ldf archive registry.

4. Step-by-Step: Manual Archive Linking for Alarm Logging

Alarm history is stored in a separate Message Archive that uses the same MDF/LDF mechanism. The linking procedure mirrors the TagLogging flow.

  1. In the WinCC Explorer, expand Alarm Logging.
  2. Expand the Archive Configuration node.
  3. Right-click Message Archive and select Link archive....
  4. Browse to the backup folder and select the alarm archive .mdf.
  5. Confirm with Open. The AlarmControl gains read access to the historical events, including acknowledgment history and operator comments.
  6. Use the AlarmControl time range filter or the WinCC Alarm Logging statistics dialog to validate the linked segment is being read.

Once linked, both trends and alarms can be queried continuously — opening and closing the picture that hosts the AlarmControl is not required, but the picture must be refreshed by toggling visibility, calling Update() via C Script, or triggering a picture change to redraw the time slider.

5. Step-by-Step: C-Script Batch Archive Connection

Linking one segment at a time is acceptable for a single backup, but a typical plant accumulates dozens of monthly archives. The community-developed batch method uses a Windows .bat file to move all desired segments into the active CommonArchiving folder in a single call, then re-queries the runtime to display the data.

5.1 Create the batch file

Create a plain text file c:\connect.bat with the following structure. Adjust the source paths and segment names to match your backup layout.

@echo off
REM --- Connect script: link all archive segments into the active project ---

REM TagLogging Fast segments
move "D:\Backups\2024-08\CommonArchiving\TLG_F_2024_08.mdf" "C:\WinCC_Projects\Plant01\CommonArchiving\TLG_F_2024_08.mdf"
move "D:\Backups\2024-08\CommonArchiving\TLG_F_2024_08.ldf" "C:\WinCC_Projects\Plant01\CommonArchiving\TLG_F_2024_08.ldf"

move "D:\Backups\2024-09\CommonArchiving\TLG_F_2024_09.mdf" "C:\WinCC_Projects\Plant01\CommonArchiving\TLG_F_2024_09.mdf"
move "D:\Backups\2024-09\CommonArchiving\TLG_F_2024_09.ldf" "C:\WinCC_Projects\Plant01\CommonArchiving\TLG_F_2024_09.ldf"

REM TagLogging Slow segments
move "D:\Backups\2024-09\CommonArchiving\TLG_S_2024_09.mdf" "C:\WinCC_Projects\Plant01\CommonArchiving\TLG_S_2024_09.mdf"
move "D:\Backups\2024-09\CommonArchiving\TLG_S_2024_09.ldf" "C:\WinCC_Projects\Plant01\CommonArchiving\TLG_S_2024_09.ldf"

REM Alarm Logging (Message Archive) segments
move "D:\Backups\2024-09\CommonArchiving\ALG_2024_09.mdf" "C:\WinCC_Projects\Plant01\CommonArchiving\ALG_2024_09.mdf"
move "D:\Backups\2024-09\CommonArchiving\ALG_2024_09.ldf" "C:\WinCC_Projects\Plant01\CommonArchiving\ALG_2024_09.ldf"

echo All segments moved successfully.

5.2 Invoke the batch file from a C action

Inside WinCC, drop a C action on a button (Global Script or picture-specific) and call the batch file with ProgramExecute():

#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
    // Launch the batch file synchronously so we know it has finished before we refresh the control
    ProgramExecute("c:\\connect.bat");

    // Optional: wait for the process to complete (up to 30 s)
    // The exact mechanism depends on WinCC version; on V7.x use WinExec + WaitForSingleObject
}

For a fully dynamic approach, generate the move lines from a C action that iterates over a configured list of source and destination paths. A loop written in C avoids the maintenance burden of editing the .bat when a new segment is added.

5.3 Refresh the OnlineTableControl

After the move commands complete, the trend and table controls need to reload the archive reference. The simplest reliable technique is a picture change — switch to another picture and switch back. In a C action this is implemented as:

// Open a different picture, then return
SetPictureName(lpszPictureName, "Overview.pdl");
// ... or directly call the picture's "Refresh" method

Alternatively, call the control's update method by name:

// Force the OnlineTableControl to reload its archive reference
HWND hWnd = FindWindow(NULL, "WinCC Runtime");
// or use the control's own IUnknown-based update if your project exposes a wrapper

Once the picture redraws, all segments that have been moved into the CommonArchiving folder become available through the standard time range dialog of the OnlineTrendControl / OnlineTableControl. The Runtime does not need to be stopped.

Disk performance: If the source backups live on a different physical disk than the active project, each move will copy the entire .mdf/.ldf pair. A 4 GB segment over a 1 GbE network share can take 30–60 s; budget the button press or scheduled task accordingly.

6. WinCC Archive Connector for RT Professional

The modern, configuration-based alternative to the C-Script batch method is the WinCC Archive Connector integrated with the WinCC DataMonitor. In TIA Portal V20 with WinCC Unified and RT Professional, the Archive Connector configures access to archive databases directly from the engineering tool — no scripting, no manual file moves.

  1. Install SIMATIC WinCC DataMonitor on the engineering station.
  2. Open the project in TIA Portal, navigate to Runtime settings > Archive Connector.
  3. Specify the path of the archive database and the archive name to be linked. The connector supports both local file paths and UNC paths to a network share.
  4. Activate the project and start RT Professional. The linked archive is exposed through the OLE DB provider and becomes queryable by the WinCC OLE DB Provider from any client subscribed to the DataMonitor web service.

For full configuration details and the OLE DB connection string syntax, see the Siemens TIA Portal V20 documentation – WinCC Archive Connector (RT Professional).

7. Archiving Parameters and Performance Tuning

The choice of archiving parameters for an archive tag directly influences CPU load on the WinCC server, disk I/O, and the responsiveness of trend and alarm queries. The following table summarises the most impactful parameters and the typical value bands recommended by Siemens.

Parameter Location (TagLogging editor) Typical Value Effect on Performance
Acquisition cycle Tag properties > Acquisition 500 ms – 1 s (Fast) / 1 s – 1 h (Slow) Lower = higher CPU, more rows, larger segments
Archiving cycle Tag properties > Archiving 1 s – 1 min Decouples storage rate from acquisition rate
Archiving type (cyclic / acyclic) Tag properties > Archiving Cyclic for analogue, acyclic for state changes Acyclic on change-of-state reduces rows for digital tags
Compression Tag properties > Compression ±0.5 % of measurement range, hysteresis, or time-based Higher compression = fewer rows = less disk I/O
Smoothing Tag properties > Smoothing None for fast control loops; 1–5 s for operator trends Reduces noise-driven archiving
Segment size Archive Configuration > Segment size 200 MB – 2 GB Smaller segments = more frequent rotation = more file handles
Segment time Archive Configuration > Segment time 1 day – 1 month Shorter segments are easier to back up individually
Archive backup target Archive Configuration > Backup Local folder or UNC path with adequate ACLs Backup must be on a volume with sufficient free space

For an in-depth treatment of how each parameter affects CPU, RAM, and disk I/O on a WinCC server, refer to the Siemens knowledge base article Archiving parameters for WinCC archive tags and their effect on performance.

8. Verification Procedures

After linking archives through any of the three methods above, run a structured verification pass before signing off the change.

  1. Confirm segment visibility in the editor. Open TagLogging and inspect the linked archive's time range. The start timestamp should match the oldest record in the imported .mdf.
  2. Query a known tag. Pick a process tag whose value at a known date is documented (e.g., a shift handover reading). Set the OnlineTableControl time range to that date and verify the row is returned.
  3. Query the alarm archive. Open the AlarmControl, set the time range to cover the linked segment, and confirm at least one historical alarm with its acknowledgment comment is displayed.
  4. Check WinCC diagnostics. Review the WinCC diagnostic files in <Project>\diagnostics\ for entries referencing CCArchiveLink or DBLink errors.
  5. Confirm Runtime stability. Leave Runtime running for at least 30 minutes after linking. A memory leak in the archive manager typically shows up as a steady increase in CCArchiveManager.exe private bytes.
  6. Document the linked segments. Maintain a spreadsheet of .mdf filename, source path, link date, and operator. This avoids accidental duplicate moves that overwrite a current segment.

9. Troubleshooting Matrix

Symptom Likely Root Cause Corrective Action
Trend shows no data after manual link OnlineTableControl picture not refreshed Toggle picture visibility, call Update() via C Script, or call SetPictureName to reload
Link dialog does not list the .mdf Wrong WinCC major version or corrupted MDF Run DBCC CHECKDB on the SQL instance holding the file, or rebuild the segment from a different backup
Move command returns "Access denied" WinCC runtime account lacks write permission on the CommonArchiving folder Grant Modify right to the WinCC service account; verify with icacls
Archive displays but rows are missing for some tags Tag was renamed after the segment was created and the original tag ID no longer exists Recreate the tag with the original name and ID, or export the segment as CSV via the Archive Connector OLE DB
C-Script ProgramExecute returns immediately and the move has not happened Antivirus blocked the spawned cmd.exe Add an exception for the WinCC project folder; verify by running the .bat manually from an elevated command prompt
Alarm archive linked, but acknowledgment comments are missing Operator workstation was on a different WinCC version at the time of the original alarm Comments are stored in the .ldf; ensure the .ldf is present and was created on a compatible build
Archive Connector (RT Professional) cannot find the database UNC path requires explicit credentials or the DataMonitor service account differs from the engineering account Configure a service account with read access; or copy the database locally and re-link
Runtime crashes shortly after linking 30+ segments SQL Server Express 10 GB ceiling reached Upgrade to SQL Server Standard, or trim old segments after export

10. Field-Proven Caveats

  • Do not edit the active archive path while Runtime is running. Changing the Archive Configuration path forces a Runtime restart on some WinCC versions; on V7.4 and later the change is hot-applied but the active trend controls lose their reference until they are re-opened.
  • Match the SQL collation. When restoring a segment from a different physical server, ensure the SQL Server instance collation matches. A SQL_Latin1_General_CP1_CI_AS host attaching a SQL_Latin1_General_CP1252_CI_AS segment will fail with error 468.
  • Read-only mount for safety. Once a backup is queried, mount the source folder read-only at the OS level to prevent an operator from accidentally modifying the master copy during a future link operation.
  • OPC redundancy. When using an Inat OPC server (as in the original context), verify that the OPC tag IDs in the linked segment match the current OPC tag IDs. Renaming a tag in the OPC server will orphan the historical rows even if the WinCC tag name is unchanged.
  • Schedule C-Script batch jobs off-peak. A ProgramExecute call that triggers a 50-segment move can saturate the disk for several minutes. Run it during a maintenance window or in response to a planned event such as a shift handover.

11. Related Best Practices

  • Define a clear naming convention for segments: <Backend>_<Year>_<Month>.mdf is easier to parse in a batch file than the default WinCC timestamp names.
  • Use the WinCC Archive Manager to schedule a daily backup copy of the active segment to a network share, rather than waiting for the monthly manual copy. This limits data exposure if a segment becomes corrupted.
  • Document the C-Script batch approach in the project Functional Design Specification (FDS) so the procedure is repeatable by maintenance staff without consulting the original integrator.
  • For WinCC Unified and RT Professional environments, prefer the Archive Connector over C-Script for new projects — the configuration-driven approach is auditable, version-controlled in TIA Portal, and free of the file-system race conditions that can affect the move approach.

Why do archived trends stay empty after I link a segment through the TagLogging right-click menu?

The OnlineTrendControl or OnlineTableControl caches the archive reference when the picture is loaded. Toggle picture visibility, call the control's Update() method from a C action, or trigger a picture change to force a reload. On WinCC V7.0 SP3 the refresh is automatic; on V7.4+ the controls require an explicit refresh.

Can I link segments that were created on a different WinCC major version?

No. The internal database schema changes between major versions (V6 → V7 → V8). A segment created on V7.x cannot be opened by a V6.2 runtime and vice-versa. Always match the major version and apply the same or higher service pack to be safe.

Do I need to stop WinCC Runtime to link archive segments?

No. Both the manual Link archive command in the WinCC Explorer and the C-Script batch method using ProgramExecute() work with Runtime running. The Trend and Table controls pick up the newly linked segments after a refresh. Stopping Runtime is only required if you are modifying the active archive configuration path itself.

How many segments can I link at once?

There is no hard-coded segment count limit in WinCC. The practical limit is the SQL Server edition: SQL Server Express bundled with WinCC caps total database size at 10 GB. For larger histories, upgrade to SQL Server Standard or use the WinCC Archive Connector to expose segments as OLE DB sources to a reporting client without re-attaching them to the active runtime.

What is the difference between the C-Script batch method and the WinCC Archive Connector?

The C-Script batch method physically moves .mdf/.ldf files into the active project and re-queries them through the WinCC archive manager — it works on WinCC V7.x. The WinCC Archive Connector is a configuration tool in TIA Portal V20 for RT Professional that exposes archived databases to the OLE DB provider without moving files, which is preferable for new WinCC Unified projects.

Back to blog