Problem Summary
After renaming a CFC chart block, a tag, or modifying the hardware configuration of an AS station in a Siemens PCS 7 project, a full download to the OS server frequently breaks the historical archive display in WinCC Runtime. The trend curves return blank, the values stop at the last good time stamp before the download, and the operator station shows "no connection", "no archive data", or simply empty curves. The archive database files (*.mdf / *.ldf) are still physically present on the OS server, but the WinCC TagLogging runtime no longer associates them with the configured archive tags.
Engineers who attempt a workaround by editing the archive tables directly in Microsoft SQL Server Management Studio (renaming the ValueName column or manually swapping ValueID entries inside the MDF) end up with a database that is detached from the SQL Server instance. The WinCC Archive Configuration editor (WinCC Explorer > Tag Logging > Archives) reports that the segment cannot be verified, and on a PCS 7 OS simulation (PLCSim / WinCC RT Simulation) the WinCC Explorer itself is not available, leaving the user without a UI to re-link the file.
This article documents three field-proven recovery paths:
- Copy the segment to the
CommonArchivingproject folder while the WinCC Runtime is running. - Attach the MDF/LDF pair manually to the SQL Server instance with
CREATE DATABASE ... FOR ATTACH, then register the segment through the WinCC Archive Configuration tool. - Restore the
ValueIDmap of the existing segment to the new tag IDs produced by the OS download, which keeps the original on-disk MDF file in place.
Root Cause: ValueID vs ValueName Mismatch
WinCC TagLogging stores every archive tag with two distinct identifiers that are decoupled from the CFC symbol name displayed in the engineering environment:
| Identifier | Scope | Persistence | Generation |
|---|---|---|---|
ValueName |
Symbolic / human-readable | Inside the dbo.Archive table of each MDF segment |
Re-created on every OS compile that triggers a TagLogging reconfiguration |
ValueID |
Numeric primary key (integer) | Inside dbo.MCPTVariable and segment headers |
Re-assigned on every full OS download that changes the tag list |
When a CFC chart is recompiled and downloaded to the AS, the corresponding WinCC tag is regenerated in the OS project. The OS Compile OS > "Tag Logging" step writes a fresh MCPTVariable row with a new ValueID for every changed tag. The on-disk MDF files still contain the previous ValueID values, and the runtime no longer knows which row corresponds to which tag. Editing the ValueName column in SQL Management Studio changes the displayed string but does not fix the ID mismatch, which is why WinCC keeps reporting "cannot verify" or silently discards the segment.
Symptoms typically observed on the OS server:
- Trend Control: curves stop at the time of the last full OS download.
- Archive Configuration: red icon next to the affected segment, message "Segment is not registered" or "Database cannot be verified".
- TagLogging RT: log file
TagLogging.rtin<WinCC_project>\ArchiveManager\TagLoggingFast\<ComputerName>\reports "no variable found for ID xxxx".
Prerequisites
Before attempting any of the three recovery methods, verify the following:
- The MDF/LDF pair belongs to the same WinCC project version (TagLogging format has not changed across WinCC V7.0, V7.1, V7.2, V7.3, V7.4, V7.5). Mixing segments from V7.1 with a V7.4 runtime corrupts the header page.
- Both files (
*.mdfand*.ldf) are present in the same folder; the LDF is required for SQL Server to bring the database to a consistent state. - The WinCC project is not write-protected and the WinCC user (typically
CCAdminor the configured runtime user) has full control on<Project>\ArchiveManagerand<Project>\CommonArchiving. - SQL Server version matches the WinCC installation. PCS 7 V8.x ships with SQL Server 2014, V9.0 with SQL Server 2016, V9.1 with SQL Server 2019. Mixing the MDF major version with the wrong SQL Server instance raises error 948 (database cannot be opened because its version is higher).
- For methods 1 and 2, the original project database is intact. For method 3, a current backup of the MDF is mandatory because the operation rewrites the
dbo.MCPTVariabletable.
Required tools:
| Tool | Purpose | Location |
|---|---|---|
| WinCC Explorer (Engineering) | Re-link segments, regenerate IDs | Engineering station only |
| SQL Server Management Studio (SSMS) | Direct MDF attachment, ID editing | OS server (full) or engineering station (sim) |
dba.exe / dbaselib |
WinCC archive maintenance CLI | <WinCC>\bin\ |
| SQL Server Configuration Manager | Verify SQL service account and start mode | OS server |
Method 1: Copy Segment to CommonArchiving Folder
This is the cleanest path when the archive segment simply needs to be re-introduced to a running runtime. WinCC automatically picks up new MDF/LDF files dropped into CommonArchiving and integrates them into the active archive database.
Procedure
- Stop any WinCC clients but leave the OS server runtime running. The ArchiveManager background process polls
CommonArchivingcontinuously. - Locate the original segment folder. By default:
<Project>\ArchiveManager\TagLoggingFast\<ComputerName>\or<Project>\ArchiveManager\TagLoggingSlow\<ComputerName>\. Inside you will find pairs such asTLG_F_20090319_153022.mdf/.ldf. - Verify file sizes: an MDF truncated mid-write is rejected. Compare the MDF size to the value reported in
ArchiveManager.xml; if it differs, restore from backup before continuing. - Copy both files into
<Project>\CommonArchiving\. Do not move them; keep the originals as a safety net. - Watch the WinCC Alarm Logging output window. Within 30–120 seconds the ArchiveManager logs a line similar to: "TagLogging: Segment TLG_F_20090319_153022 attached successfully".
- Open the OS runtime Trend Control and request the affected tag. Historical values up to the time of the last good segment boundary should reappear.
If the log shows "Segment TLG_F_xxx ignored: unknown tag ID yyyy", the segment references a ValueID that no longer exists. Drop the segment from CommonArchiving and switch to Method 3 (ID restoration) or Method 2 (manual attach with reconfiguration).
Method 2: Manual SQL Server ATTACH DATABASE
Use this method when the segment has been moved out of the project tree, was edited in SQL Management Studio, or when CommonArchiving refuses the file because the MDF is already registered in the SQL instance under a different logical name.
Step-by-step T-SQL procedure
- Open SSMS and connect to the WinCC instance:
WINCC<inst>\SQLEXPRESSorWINCC, depending on the PCS 7 version. The instance name is configured in the SQL Server Configuration Manager. - Identify the logical name and physical path of the database. Run on the master context:
SELECT name, physical_name, state_desc FROM sys.master_files WHERE database_id = DB_ID('CC_TL_F_2009_03_19_15_30_22'); - Detach the database if it is currently attached:
USE master; GO EXEC sp_detach_db @dbname = N'CC_TL_F_2009_03_19_15_30_22'; GO - Copy the MDF and LDF pair into the WinCC archive directory expected by the project, e.g.
<Project>\ArchiveManager\TagLoggingFast\<ComputerName>\. - Attach the database back to the SQL instance. Microsoft Learn: Attach a Database (SQL Server) documents the full syntax. The minimum form is:
When you select the .mdf file in the SSMS Attach Databases dialog, the LogicalName, InitialSize, and Owner fields are filled automatically from the file header; review the Owner column to ensureUSE master; GO CREATE DATABASE [CC_TL_F_2009_03_19_15_30_22] ON (FILENAME = N'C:\Programs\Siemens\Automation\WinCC\ArchiveManager\TagLoggingFast\Server01\TLG_F_20090319_153022.mdf'), (FILENAME = N'C:\Programs\Siemens\Automation\WinCC\ArchiveManager\TagLoggingFast\Server01\TLG_F_20090319_153022.ldf') FOR ATTACH; GOCCAdminor the WinCC service account is set. - Verify the database is online and TRUSTWORTHY (required for WinCC cross-database queries):
SELECT name, state_desc, is_trustworthy_on FROM sys.databases WHERE name = N'CC_TL_F_2009_03_19_15_30_22'; ALTER DATABASE [CC_TL_F_2009_03_19_15_30_22] SET TRUSTWORTHY ON; GO - Return to the engineering station. Open WinCC Explorer > Tag Logging > Archives. Right-click the archive and select "Update / Reload". The newly attached segment should appear with a green status icon.
- Trigger an OS Compile OS > Tag Logging. This rewrites the
MCPTVariablerows in the active database but does not touch the historical segment just attached.
Common SSMS error mapping
| SSMS / SQL Error Code | Message | Cause | Action |
|---|---|---|---|
| 5120 | Unable to open the physical file | File-system ACL on MDF/LDF | Grant Modify on the folder to the SQL Server service account (NT SERVICE\MSSQL$WINCC or local system on legacy installs) |
| 5171 | ... is not a primary database file | LDF/MDF swapped or corrupted header page | Re-copy from backup; do not use a partial download |
| 5123 | CREATE FILE encountered operating system error 5 | WinCC archive manager has the file open | Stop WinCC Runtime, retry, restart Runtime |
| 948 | The database cannot be opened because its version is higher | MDF from a newer SQL / WinCC version | Use a matching SQL Server instance or restore from the older format via WinCC dbaselib export |
| 3624 | A system assertion check has failed | MDF is suspect (mid-write crash) | Restore from *.bak produced by dba.exe; emergency mode repair only as last resort |
For SSMS GUI users, right-click Databases > Attach > Add, browse to the MDF, and confirm the database details before clicking OK. Microsoft Learn: Attach a Database (SQL Server) describes the dialog fields (Database name, Owner, Reattach files, MDF/LDF rows) in detail.
Method 3: Restoring Old ValueIDs in the Segment
This is the most surgical fix and is appropriate when the engineer does not want to touch the SQL Server instance and prefers to keep the original MDF exactly as it is, simply updating the ValueID integers so the new WinCC project can read it.
- Stop the WinCC Runtime to release the file lock on the MDF.
- Make a working copy of the segment. Rename it from
TLG_F_20090319_153022.mdftoTLG_F_20090319_153022_orig.mdfand use the copy for editing. - Open the working MDF in SSMS as a user database. Run a query that lists the current mapping between ID and Name:
USE [CC_TL_F_2009_03_19_15_30_22]; GO SELECT ValueID, ValueName, Archiving FROM dbo.MCPTVariable ORDER BY ValueID; - Open the new WinCC project (engineering station) and read the freshly generated IDs. The TagLogging editor exposes them through the internal view
dbo.MCPTVariableof the active database. The simplest field-proven approach is to query both databases side by side in SSMS, build a mapping table (old ID → new ID) and update the historical segment in one transaction. - Apply the renumbering. The pattern below renames the IDs inside the segment so that the values previously stored under ID 4711 are now found under the new project's ID 5032:
BEGIN TRANSACTION; UPDATE dbo.MCPTVariable SET ValueID = 5032 WHERE ValueID = 4711 AND ValueName = N'MOTOR_SPEED'; -- Repeat for each affected tag COMMIT; - Re-attach the modified segment to the WinCC instance using the
FOR ATTACHsyntax from Method 2, then move it back intoArchiveManager\TagLoggingFast. - Restart the WinCC Runtime. Open the Trend Control, request the renamed tag, and confirm that the historical curve resumes at the old time stamp.
dbo.MCPTVariable must be done outside the active runtime. Editing the table while the TagLogging RT has the database open causes a torn write and is the single most common cause of "database is marked RESTORING" errors after a recovery attempt.OS Simulation (PLCSim / WinCC RT Simulation) Limitations
When the affected runtime is a PCS 7 OS simulation started from SIMATIC Manager, the following constraints apply and drive the choice of method:
- WinCC Explorer is not installed on the simulation host. Configuration changes (TagLogging > Archives, OS Compile) must be done on the engineering station, then the project is reloaded into the simulator.
- The simulation host uses SQL Server Express, which has a 10 GB per-database limit. Long-running archives quickly approach it, and partial MDF files are common after a hard reset of the simulator.
- CommonArchiving on a simulator is not auto-monitored unless the WinCC RT is started in service mode. In interactive mode, manually trigger an OS Compile OS > Tag Logging after the copy.
- Method 3 (ValueID restoration) is the most reliable on a simulator because the source and target MDFs are typically small and can be copied off the simulator host for offline editing.
Verification Procedure
After any of the three recovery methods, perform the following checks before handing the system back to operations:
- Open WinCC Explorer > Tag Logging > Archives on the engineering station and confirm every segment carries a green icon. Red or yellow icons must be investigated before commissioning.
- Start the OS Runtime. Open the Trend Control and load a tag that was renamed. The curve must show continuity across the OS download time stamp.
- Inspect the TagLogging runtime log at
<Project>\ArchiveManager\TagLoggingFast\<ComputerName>\TagLogging.rt. Entries containing ERROR or WARN within 15 minutes of restart are abnormal. - Validate the database consistency from SSMS:
DBCC CHECKDB(N'CC_TL_F_2009_03_19_15_30_22') WITH NO_INFOMSGS; - Confirm the SQL Server job WinCC_Archive_Backup (or the equivalent dbaselib schedule) ran successfully for the re-attached segment.
- For redundant OS server pairs, perform a failover and repeat the verification on the standby to ensure the segments are present on both nodes.
Preventive Measures and Best Practices
- Enable WinCC Archive Configuration option "Allow tag name change without losing history" (WinCC V7.3 and later) so that renaming a tag in the CFC keeps the original
ValueID. - Perform incremental OS downloads (delta compile) instead of full downloads whenever possible. A delta download preserves
ValueIDs for unchanged tags. - Use the dbaselib scheduled job to export archive segments to backup before any full OS download. A typical schedule is daily full export plus a 4-hour differential export.
- Document every tag rename in the project change log with the old/new
ValueIDand the time stamp of the corresponding OS download. - Configure a redundancy partner for the OS server in PCS 7 V8.2 SP1 and later so that the archive manager can fall back to a verified copy of the segment if the primary is corrupted.
- Set the SQL Server service account to a domain user with explicit modify rights on
ArchiveManagerto avoid 5120 errors after the recovery.
Troubleshooting Matrix
| Symptom in WinCC Runtime | Probable Cause | First Action | Escalation |
|---|---|---|---|
| Trend curve empty after OS download | ValueID regenerated for renamed tag | Open TagLogging.rt; check for "no variable for ID" |
Apply Method 3 (ValueID restoration) |
| Archive Configuration shows red icon for segment | MDF not registered in SQL instance | Verify MDF/LDF in expected folder | Use Method 2 (FOR ATTACH) or drop to CommonArchiving (Method 1) |
| SSMS reports 5120 on attach | File-system ACL | Check owner of MDF; grant Modify to SQL service account | Stop Runtime, retry, verify with sys.master_files
|
| SSMS reports 948 on attach | SQL Server version lower than MDF | Check MDF header version with DBCC CHECKDB on a matching instance |
Reinstall matching SQL Server or use dba.exe export to downgrade |
| Runtime starts but archive warnings in log | TRUSTWORTHY off on attached DB | ALTER DATABASE ... SET TRUSTWORTHY ON |
Restart WinCC RT, re-check sys.databases
|
| Trend shows old values but stops at OS download | Tag renamed, ValueID changed but history preserved | Open Trend Control, select tag by Name; check Archive Configuration for the new ID | Add a new trend view referencing the new ID, or apply Method 3 to bridge |
| CommonArchiving copy is ignored | Runtime not polling folder / file lock | Confirm WinCC RT running, CCAdmin rights on folder |
Drop to ArchiveManager subfolder and trigger OS Compile OS |
Field-Commissioning Notes
During brownfield commissioning, schedule the OS download during a planned downtime, immediately followed by:
- Full archive export through dba.exe (
dba.exe /export /path C:\Backup\Archives). - Re-attach verification on the engineering station using the steps in Method 2.
- A 24-hour soak test of the Trend Control with at least three renamed tags before plant hand-back.
For greenfield projects, use the PCS 7 "OS Project Editor" with the option Create archive structure for all AS tags enabled. This pre-generates a stable ValueID map before the first runtime start, eliminating the mismatch from the start.
Why does WinCC show "database cannot be verified" after a renamed tag is downloaded?
The TagLogging runtime regenerates the numeric ValueID of every changed tag during an OS Compile. The on-disk MDF segment still references the old ID, so the header check fails. Re-link the segment with the CREATE DATABASE ... FOR ATTACH T-SQL statement and either restore the old ID inside the segment (Method 3) or accept the new ID and let WinCC show only post-download history.
Can I simply copy the MDF file into the ArchiveManager folder without touching SQL Server?
Yes, if the runtime is active and the file pair is dropped into <Project>\CommonArchiving\. WinCC attaches it automatically. If the file is placed directly in ArchiveManager\TagLoggingFast while the runtime is stopped, the segment is not picked up until the next OS Compile OS or until you use SSMS to attach it.
What SQL Server permission is required to attach an MDF in PCS 7?
The SQL Server service account (typically NT SERVICE\MSSQL$WINCC) must have Modify rights on the folder holding the MDF and LDF. The SSMS user attaching the database needs the dbcreator server role or explicit CREATE DATABASE permission; the WinCC engineering user CCAdmin is granted this role by default.
Is the WinCC Explorer available on a PCS 7 OS simulation?
No. A simulation started from SIMATIC Manager runs WinCC Runtime only. Configuration changes (TagLogging, Alarm Logging, Graphics Designer) must be performed on the engineering station, and the project reloaded into the simulator through OS Compile OS > "Download" before the change is visible in the runtime.
How do I prevent the ValueID mismatch on the next full OS download?
Enable "Allow tag name change without losing history" in the TagLogging editor (WinCC V7.3 SP2 and later), use delta downloads instead of full downloads, keep an up-to-date dbaselib export as backup, and document every tag rename with its old and new ValueID in the project change log.