Resolving WinCC V6 SP3 User Archive C0000005 Access Violation
A Siemens WinCC V6 SP3 runtime in production is logging C0000005 ACCESS_VIOLATION faults from the script engine, ExecuteError events in configured actions, and a parallel Failed to switch archive (Type:1) message from ArchiveManager that targets the long-term tag archive file PETRON_SERVER_PETRON#HMI#22_ALG_200707221601. The visible result is a User Archive editor window that shows zero rows even though the database file is present on disk and the configured validation logic depends on that table to make plant objects visible. The combination of these three symptom classes points to a corrupted or detached User Archive database, almost always caused by a crash of the script engine that has left the WinCC ODBC connection pool in an invalid state and corrupted the in-memory OLE-DB cursor that feeds the User Archive table view. The remedy is a structured recovery that combines a script fault review under APDIAG, a manual reset of the archive swap, and a forced re-link of the User Archive data source to its underlying Microsoft SQL Server database.
Problem Summary
Before opening any tool, classify the symptoms. The reported project (computer name PETRON_SERVER, server prefix PETRON, HMI tag prefix HMI) presents four distinct, correlated symptoms. They are listed in the order in which they should be cleared; failure to clear the lower layers first causes the higher layers to fail again on the next runtime start.
| Layer | Observed Symptom | Source File | Error Code | Indicates |
|---|---|---|---|---|
| Script engine | Unhandled exception in action | WinCC_Sys_*.log |
C0000005 ACCESS_VIOLATION @ 0x00429ADA | Memory access into invalid address; C or VBS runtime terminated |
| Action dispatcher | ExecuteError in Action @3 | APLog |
1007001 / 4 | Third configured action threw; dispatcher disabled the action |
| Archive Manager | Failed to switch archive (Type:1) | APLog |
0 / 4 | Tag-archive swap to ..._ALG_YYYYMMDDHHMM failed |
| User Archive editor | Empty list, no records visible | Graphics / WinCC Explorer | - | User Archive control could not bind to its data source |
ExecuteError, and the configured action is placed in an error state. The next start of that action will repeat the same fault unless the underlying data source is repaired. Stop the WinCC runtime before changing configuration files or databases.Interpreting the C0000005 ACCESS_VIOLATION
The Windows NT status code 0xC0000005 (decimal -1073741819) is the standard STATUS_ACCESS_VIOLATION raised by the memory manager when a thread attempts to read from, write to, or execute an address for which the process has no valid page-table entry. The log fragment taken from the WinCC diagnose folder is:
// WinCC reported exception with code: C0000005 ACCESS_VIOLATION
// Date: 19.07.2007 - Time: 05:31:48
// Caused at logical address 00429ADA 01:00028ADA
Decoding the addresses:
-
00429ADAis the absolute virtual address inside the WinCC process. The leading00400000range is the typical load address for the script runtime DLL shipped with WinCC V6 SP3, which means the faulting instruction is insidescript.dllorpdlrtapi.dll, not inside a third-party OCX. -
01:00028ADAis the module/offset pair.01is the module ordinal of the executable image that contained the faulting instruction, and00028ADAis the byte offset into that module's code section. In practice the second number is the address you hand to WinCC support when opening a ticket.
Causes that match this exact pattern in WinCC V6 SP3, in descending order of frequency:
- A C action dereferences a pointer obtained from a
GetTag*call after the tag has been deleted from the data manager or has not yet been created. The dispatcher'sExecuteErroris raised, the pointer is freed, and a later access into the same address by the cleanup code raises the access violation. - A VBS action evaluates a non-array variable as an array, e.g.
UBound(EmptyValue)orSplit(NULL), which causes the VBScript engine to fault inside the VBScript5.dll address range. - A User Archive script calls
uaQueryOpen/uaQueryClosein the wrong order, leaking handles until the OLE-DB cursor pool is exhausted and a subsequent call returns an invalid pointer. - SQL Server connectivity is broken. The User Archive connection string points to a server that has been moved, renamed, or whose service account has been changed. WinCC V6 SP3 falls back to a stub client that returns zero rows and surfaces ACCESS_VIOLATION the first time the script touches the cursor.
- A hot-fix or service pack was applied on top of SP3 without re-installing the matching
WinCC_SQL_Server.mdfschema migration. TheUAtable exists but the expected columns are missing.
Interpreting the ArchiveManager "Failed to switch archive (Type:1)"
The ArchiveManager message
255,22.07.2007,23:55:01:984,0,4,,PETRON_SERVER,ArchiveManager,Failed to switch archive(Type:1):PETRON_SERVER_PETRON#HMI#22_ALG_200707221601 !
breaks down as follows:
| Field | Value | Meaning |
|---|---|---|
| Severity | 255 | Internal error, dispatcher cannot continue |
| Date / Time | 22.07.2007 23:55:01.984 | Local server time when the swap was attempted |
| Process ID | 0 | WinCC ArchiveManager thread |
| WinCC error number | 4 | DM_ERROR_FILE_CREATE (file could not be created or opened) |
| Computer | PETRON_SERVER | Server name from the project |
| Component | ArchiveManager | Subsystem that raised the entry |
| Message | Failed to switch archive (Type:1):PETRON_SERVER_PETRON#HMI#22_ALG_200707221601 | The long-term file for tag-archive HMI#22 on 22 July 2007 at 16:01 could not be created |
WinCC archives are numbered by type:
| Type | Name | File mask | Backing store |
|---|---|---|---|
| 1 | Tag archive | <Server>_<Prefix>#<ArchiveNo>_ALG_YYYYMMDDHHMM |
SQL Server database CC_PT2K_070322_165831
|
| 2 | Alarm archive | <Server>_<Prefix>#<ArchiveNo>_ALG_YYYYMMDDHHMM |
SQL Server database CC_ALG_070322_165831
|
| 3 | User Archive | n/a (in-database table) | SQL Server database CC_UA_070322_165831
|
The failure almost always means the underlying SQL Server database is detached, full, or its transaction log is exhausted. WinCC's archive swap operation is a single transaction inside SQL Server: if the transaction cannot commit, the long-term file is not created, the active segment is not closed, and the dispatcher records DM_ERROR_FILE_CREATE (4). The next swap attempt runs into the same condition and the in-memory segment overflows within hours, which is why the User Archive list goes empty: the data source cursor is no longer valid.
Diagnostic Procedure with APDIAG
APDIAG (WinCC Advanced Diagnostics) is the OEM tool that turns on continuous script tracing and crash dump generation. It is installed automatically on every WinCC V6 SP3 server but the service is disabled by default. Enable it from the Windows service control panel:
- Open
services.mscand locate CCAlgChnService, CCArchiveManager, and CCUAChnService. Set each to Automatic and start them. - Start WinCC Explorer and open Tools > APDIAG. If the menu entry is missing, run
APDIAG.EXEfrom%ProgramFiles%\Siemens\WinCC\bin. - Switch to the Traces tab and enable the ScriptEngine, ArchiveManager, and UserArchive channels. Set the trace level to Maximum and the file size to 50 MB per channel.
- Reprocess the failing action. APDIAG writes a binary dump of the script process to
...\WinCC\diagnose\APDIAGevery time the dispatcher logs an ExecuteError. The dump file has the same module/offset pair as the ACCESS_VIOLATION log entry, so the two can be correlated by timestamp.
Logfile Location and Analysis
All WinCC V6 SP3 log files are stored in the project diagnose folder. The default path is:
C:\Program Files\Siemens\WinCC\WinCCProjects\<ProjectName>\diagnose\
C:\Program Files\Siemens\WinCC\diagnose\
C:\Program Files\Siemens\WinCC\bin\..\..\diagnose\
The files relevant to this failure are:
| File | Contains | Rotation | Action when present |
|---|---|---|---|
WinCC_Sys_01.log … WinCC_Sys_99.log
|
System-level events and unhandled exceptions including ACCESS_VIOLATION | 5 MB per file, 99 files | Open with WinCC Diagnosis viewer; cross-reference time and module offset |
APLog |
ArchiveManager, AlarmLogging, UserArchive messages | Single rolling file | Filter on ArchiveManager and UserArchive |
APDIAG_*.dmp |
Crash dump of the script process | Created on demand | Open in WinDbg with the matching .pdb symbols |
Script.log |
C and VBS script compile and runtime errors | 5 MB per file, 5 files | Look for the action ID that raised ExecuteError |
CCArchiveManager.log |
Archive swap transactions, including DM_ERROR_FILE_CREATE | 10 MB per file, 5 files | Search for Failed to switch |
When analysing the logs for the symptom set above, use the following filter sequence in WinCC Diagnosis:
- Filter on
C0000005. Every entry is an unhandled exception; record the address and the timestamp. - Filter on
ExecuteError. Every entry is an action that was disabled by the dispatcher; record the action index. - Filter on
Failed to switch archive. Every entry corresponds to a long-term file that was not created; record the file mask and the SQL Server error number (last field of the line). - Filter on
uaQuery/uaArchive. This isolates the User Archive activity and confirms whether the OLE-DB cursor was open at the moment the script crashed.
SQL Server and User Archive Database Verification
WinCC V6 SP3 stores its runtime data in a Microsoft SQL Server 2000 instance named WinCC. The instance is created during installation and hosts three databases that are critical to User Archive operation:
| Database | Purpose | Default size | Recovery model |
|---|---|---|---|
CC_<Project>_<Timestamp> |
Configuration and project data | 50 MB | Simple |
CC_PT2K_<Timestamp> |
Tag archive runtime data (Type 1) | 500 MB auto-grow | Simple |
CC_UA_<Timestamp> |
User Archive runtime data (Type 3) | 50 MB | Simple |
Verify each database from the command line of the server:
- Open a command prompt and run
osql -E -S PETRON_SERVER\WinCCto connect with the trusted administrator context. - At the
1>prompt, runSELECT name, state_desc, recovery_model_desc FROM sys.databases WHERE name LIKE 'CC%';. The state_desc column must readONLINEfor every database. A state ofRECOVERING,RESTORING, orSUSPECTindicates the cause of the failed archive swap. - Run
DBCC CHECKDB('CC_UA_<Timestamp>') WITH NO_INFOMSGS;on the User Archive database. A consistency error result confirms that theUAtable is corrupt and the empty User Archive editor is a direct consequence. - Run
EXEC sp_spaceused;on the tag-archive database. Ifdatais within 5 percent ofdatabase_sizeandunallocated spaceis zero, the transaction log has filled the file. The next archive swap will raise DM_ERROR_FILE_CREATE. - Exit with
quitand review theSQLAGENT.OUTandERRORLOGfiles inC:\MSSQL7\LOGfor any failure messages that pre-date the WinCC diagnose entries.
CC_PT2K or CC_UA database from SQL Server. Detaching is the only way WinCC V6 SP3 recognises the file as missing and refuses to re-attach. Use the in-place repair procedure described below.User Archive Re-link Procedure
If DBCC CHECKDB reports consistency errors on the User Archive database, the data source must be re-linked. The procedure does not require a project rebuild and preserves the table contents.
- Stop the WinCC runtime:
net stop "CCArchiveManager",net stop "CCUAChnService",net stop "CCAlgChnService". - Back up the User Archive database:
BACKUP DATABASE [CC_UA_070322_165831] TO DISK = N'D:\Backup\CC_UA_pre_repair.bak' WITH INIT; - Run the in-place repair:
DBCC CHECKDB('CC_UA_070322_165831', REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS; - Re-index the User Archive table:
DBCC DBREINDEX('UA', '', 90); - Update the WinCC statistics:
UPDATE STATISTICS UA WITH FULLSCAN; - Start the services in reverse order:
net start "CCAlgChnService",net start "CCUAChnService",net start "CCArchiveManager". - Re-start the WinCC runtime and open the User Archive editor. The list should now display the expected rows.
Script Engine Repair
The script-engine ACCESS_VIOLATION is a downstream effect. After the User Archive database is repaired, the offending action must be hardened so that the same fault is not raised on the next trigger.
Common patterns and the corresponding fixes for WinCC V6 SP3 C and VBS actions:
| Pattern | Failure mode | Hardened replacement |
|---|---|---|
float val = GetTagFloat("HMI/Valve_1"); |
Tag missing → pointer dereference of NULL | DWORD q; float val = GetTagFloat("HMI/Valve_1", &q); if (q & 0x04) return; // quality bad |
Dim arr() As Variant |
Empty variant → VBScript5 fault | If IsEmpty(arr) Or Not IsArray(arr) Then Exit Sub |
uaQueryOpen(1, h)' ... no uaQueryClose |
Cursor leak → pool exhausted | Wrap in On Error Resume Next and call uaQueryClose in the ApExit action |
Set rs = uaArchiveGetRecordset(1)' rs used after DBCC shrink |
Detached cursor → invalid pointer | Re-open the recordset at the top of the action; never cache a recordset across triggers |
SQLConnect("CC_PT2K_070322_165831") |
DB name changed after SP3 hotfix | Use SQLConnect("CC_PT2K_<current timestamp>") read from registry HKLM\SOFTWARE\Siemens\WinCC\SQL\Databases
|
For the failing action index 3, the typical configuration is a periodic action triggered every 5 seconds that polls the User Archive for validation rows. Re-implement it as a self-guarded action that only reads when the archive connection reports DB_OK:
' Action 3 - guarded User Archive poll
Dim hArchive, bOk, lCount
bOk = uaQueryOpen(1, hArchive)
If Not bOk Then
' connection failed; disable action to stop the dispatch loop
SetOperationMode 0
Exit Sub
End If
lCount = uaQueryGetFieldValueCount(hArchive)
If lCount > 0 Then
' bind to the picture and set visibility
SetVisible "HMI/Object_42", True
End If
uaQueryClose hArchive
Archive Configuration Reset
The Failed to switch archive message leaves the active segment of the tag archive in a half-closed state. Closing it manually restores the swap mechanism without losing data.
- Open WinCC Explorer > Tag Logging and select the archive that owns
HMI#22. - Right-click the archive and choose Properties > Archive Configuration. Verify the segment size (default 1 day) and the swap action (default Automatic).
- Switch the swap action to Manual and click Apply. WinCC closes the current segment and opens a new one.
- Switch the swap action back to Automatic and click OK.
- Inspect the ArchiveManager tab in WinCC Diagnosis. The
Failed to switch archiveline should be replaced by aSwitched archiveentry with the new timestamp.
Step-by-Step Resolution Procedure
The full recovery sequence combines the four procedures above into a single controlled change window.
-
Capture state. Export the WinCC project, the diagnose logs, and the
CC_PT2KandCC_UAdatabases. Keep the export inD:\Backup\pre_repair_<date>\. - Stop the runtime. Stop all WinCC services and the runtime. The dispatcher will not log ExecuteError while the runtime is down, so the APDIAG log will be clean from this point forward.
- Run APDIAG. Enable the ScriptEngine, ArchiveManager, and UserArchive trace channels. Set the buffer to 50 MB and start the runtime in Diagnosis mode.
-
Verify SQL Server. Run the four
osqlqueries from SQL Server and User Archive Database Verification. Record the state_desc of each database and the result ofDBCC CHECKDBonCC_UA. - Repair the User Archive database. Run the re-link procedure from User Archive Re-link Procedure. Use REPAIR_ALLOW_DATA_LOSS only after the database backup is verified.
- Close the half-open tag archive segment. Follow the Archive Configuration Reset steps to trigger a manual swap and verify the new Switched archive entry in the diagnose log.
- Harden the offending action. Replace Action 3 with the guarded pattern from Script Engine Repair. Re-compile the project and check the Script.log for clean compile.
- Restart the runtime. Bring the services back up in the reverse order. Open the User Archive editor and confirm the row count matches the expected value.
-
Run a soak test. Leave APDIAG running for 24 hours and check that the
C0000005counter is zero, theExecuteErrorcounter is zero, and theFailed to switch archivecounter is zero. - Remove APDIAG. Once the soak test is clean, switch the trace channels back to Off and stop the APDIAG service.
Verification Tests
After the resolution procedure, run the following checks to confirm the system is healthy. A test that fails indicates a residual problem and must be cleared before the runtime is returned to production.
| Test | Tool | Expected result | Threshold |
|---|---|---|---|
| Open User Archive editor | WinCC Explorer > User Archive | Row count matches the SELECT COUNT(*) on CC_UA.dbo.UA
|
Exact |
| Trigger validation action | Force a trigger of Action 3 | Object becomes visible within 5 s | ≤ 5 s |
| Watch the dispatcher |
APLog filter on ExecuteError
|
No entries for 24 h | 0 |
| Watch the archive manager |
APLog filter on Failed to switch
|
No entries for 7 days | 0 |
| Script engine fault counter | APDIAG > Statistics > ScriptEngine | No C0000005 entries |
0 |
| SQL Server consistency |
DBCC CHECKDB on all CC_* databases |
Clean | 0 consistency errors |
| Archive swap | WinCC Explorer > Tag Logging > Manual swap | New _ALG_ file created |
1 per swap attempt |
| Tag archive write rate | WinCC Diagnosis > Performance | Write rate within published limits | ≤ 5000 values/s sustained |
Prevention and Hardening
The conditions that produce the symptom set above are all preventable. The following controls should be in place on every WinCC V6 SP3 server before commissioning.
-
Pin the SQL Server recovery model. Use the Simple model for the
CC_PT2KandCC_UAdatabases unless point-in-time restore is a contractual requirement. Simple model truncates the transaction log on every checkpoint, removing the most common cause of DM_ERROR_FILE_CREATE. -
Cap tag-archive retention. Limit each tag archive to 30 days online. Long-term storage is the job of the
_ALGfiles, which can be exported to NAS for offline browsing. -
Guard every User Archive read. Wrap
uaQueryOpenin a quality check. If the connection returnsFALSE, the script mustExit Subrather than touch the cursor. -
Compile actions with Strict On. VBS actions compiled with
Option Explicitand Strict mode do not silently allow the empty-Variant-to-array cast that triggers the VBScript5 fault. -
Schedule a daily SQL Server consistency check. A SQL Server Agent job that runs
DBCC CHECKDB('CC_UA_<TS>')at 02:00 and writes the result to the Windows Application event log surfaces corruption before the next archive swap. - Run APDIAG for one week after every change. A change to the project, the database, the SQL Server, or the OS must be followed by seven days of ScriptEngine and ArchiveManager traces. The trace logs are the only artefact that correlates a script-engine crash with the archive swap that followed it.
- Lock the WinCC project. In WinCC Explorer > Project > Properties > Options, enable Disable project changes on the server. This prevents a stray editor from renaming a tag while the runtime is in operation.
Component Cross-Reference
The following table maps each symptom in this article to the WinCC V6 SP3 component that owns the file or registry key involved in the fix. The version numbers correspond to the build that was current on the date of the reported failure (SP3, build 070322, released 22 March 2007).
| Component | Executable / DLL | Build | Service |
|---|---|---|---|
| Script engine | script.dll |
070322.1658 | CCAlgChnService |
| Archive Manager | ArchiveManager.exe |
070322.1658 | CCArchiveManager |
| User Archive | UAChn.dll |
070322.1658 | CCUAChnService |
| Tag Logging | CTLChn.dll |
070322.1658 | CCAlgChnService |
| Diagnostics | APDIAG.EXE |
070322.1658 | n/a (interactive) |
| SQL Server runtime | sqlservr.exe |
8.00.2039 (SP4) | MSSQLServer |
Frequently Asked Questions
What does the C0000005 ACCESS_VIOLATION log entry mean in WinCC V6 SP3?
C0000005 is the Windows NT STATUS_ACCESS_VIOLATION code, raised when a script engine thread reads, writes, or executes an invalid address. In WinCC V6 SP3 it is logged in WinCC_Sys_*.log together with a module/offset pair, e.g. 01:00028ADA, which identifies the exact instruction that caused the fault. The dispatcher will disable the action that raised it.
Where are the WinCC V6 SP3 diagnose log files stored?
The default location is C:\Program Files\Siemens\WinCC\WinCCProjects\<ProjectName>\diagnose\ for project logs and C:\Program Files\Siemens\WinCC\diagnose\ for system logs. The relevant files are WinCC_Sys_*.log for the exception, APLog for ArchiveManager, and Script.log for compile and runtime errors.
How do I start the APDIAG tool?
Start APDIAG.EXE from %ProgramFiles%\Siemens\WinCCin, or open it from Tools > APDIAG in WinCC Explorer. Enable the ScriptEngine, ArchiveManager, and UserArchive trace channels, set the level to Maximum, and reproduce the failure. APDIAG writes a crash dump to the diagnose folder for every ExecuteError.
How do I recover a User Archive that shows zero rows in the editor?
First verify the CC_UA_<Timestamp> database with DBCC CHECKDB in osql. If the result reports consistency errors, back up the database, run DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS, re-index the UA table, and update statistics. Restart the WinCC runtime; the User Archive editor will repopulate.
How can I prevent the Failed to switch archive (Type:1) error from recurring?
Set the CC_PT2K database to the Simple recovery model, increase the transaction log to at least 2 GB, and cap online tag-archive retention to 30 days. A SQL Server Agent job that runs DBCC CHECKDB on all CC_* databases daily will surface corruption before the next archive swap.