WinCC AlarmLog Operator Comments: CSV Export Property Guide

David Krause14 min read
HMI / SCADASiemensTroubleshooting
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

Exporting operator-entered alarm comments from a Siemens WinCC runtime project to a CSV file is a recurring requirement for shift reports, regulatory audits, and root-cause analysis. The most common failure point is the assumption that the LoggedAlarmStateResult class exposes a Comment (or Comments) property analogous to UserName, Time, or State. The property does not exist on the OLE DB result set in the way the operator is trying to read it, so the script silently produces a row missing the comment column, or fails at runtime with an Object doesn't support this property or method error. This reference details the WinCC V7 alarm logging architecture, the OLE DB provider interface, and a working code path to extract comments from the underlying SQL Server runtime database and write them to a CSV alongside the alarm log.

Problem: Operator Comments Not Exported with WinCC Alarm Log

A VBScript in a WinCC V7 project is iterating through alarm states returned by the OLE DB provider and writing them to a CSV file. Operators add comments through the WinCC AlarmControl (right-click → Acknowledge with comment or via the AlarmLogging.AddComment() API). The script is correctly capturing columns such as MsgNr, Time, MS, State, UserName, and ComputerName. When the operator adds the line loggedAlarmState.Comments to the row assembly, the script fails to produce a value or breaks entirely. Disabling that single line restores the export. The challenge: the comment is being saved by the runtime (it is visible in the AlarmControl), but the property path is wrong for the read operation.

Root Cause: LoggedAlarmStateResult Property Limitations

The LoggedAlarmStateResult class (returned by AlarmLogging.QueryLogs() and equivalent OLE DB queries) is a flattened projection of the alarm state row. Its members are bound to the columns of the WinCC runtime database and are documented in the WinCC Information System under Working with WinCC > ANSI-C and VBScript in WinCC > OLE DB Provider for WinCC. The standard set of properties exposed by the runtime OLE DB provider includes:

Property Type Description
MsgNr Long Configured message number
State Long Alarm state: 1 = Came In, 2 = Went Out, 3 = Acknowledged, 4 = Status, 6 = Status acknowledged
Time Date UTC timestamp of the state change
MS Long Milliseconds component of the timestamp
Instance String Instance identifier (e.g., tag instance)
Counter Long Internal counter assigned by the runtime
UserName String User that performed the action
ComputerName String Server or client originating the event
AckType Long Acknowledgement type (single, multi, emergency)
Comment String Operator comment — availability is version-dependent

The Comment field is only populated on the state row that was created at the moment the comment was entered (typically the Acknowledged state, value 3, or a dedicated comment state). On the Came In or Went Out states for the same message, the comment column is empty. The OLE DB provider therefore returns the comment on a specific row, not as a property of the alarm message. If the iterating script is on the wrong state row, the column is genuinely empty.

In TIA Portal WinCC Professional, the field is sometimes mapped to CommentText, OperatorComment, or stored in a parallel table joined via the alarm state key. The mismatch between what the API name suggests (Comments, plural) and what the schema actually provides is the root of the error.

WinCC V7 Alarm Logging Architecture and the OLE DB Interface

WinCC V7 stores runtime alarm data in a SQL Server database whose instance name is by default .\WinCC (SQL Server Express bundled with WinCC). The default database location is <ProjectPath>\SQL\<ServerName>\. The runtime database is segmented by time and the catalog name reflects the segment timestamp:

Provider=WinCCOLEDBProvider.1;Catalog=CC_<ProjectName>_<YYYY-MM-DD>_<HH-MM-SS.SSS>;Data Source=.\WinCC

Archived (closed) segments are exposed under the CC_OpenArch_ prefix and can be queried even after the runtime has rolled forward:

Provider=WinCCOLEDBProvider.1;Catalog=CC_OpenArch_<YYYY-MM-DD>_<HH-MM-SS.SSS>;Data Source=.\WinCC

The runtime catalog is recreated on every project start. A long-running export script that hard-codes a catalog name will fail after the next restart because the catalog timestamp changes. The accepted pattern is either to enumerate the available catalogs at script start, or to query the archive catalog for stable, historical references such as the operator comment.

The AlarmLogging COM object exposed by WinCC provides write-side methods only — AddComment(), UpdateComment(), and DeleteComment(). There is no ReadComment() on the COM interface. Comments must be read from the SQL Server view that wraps the runtime segments. The relevant Siemens reference for the read path is the WinCC Information System under Working with WinCC > ANSI-C and VBScript in WinCC > OLE DB Provider for WinCC > Querying the Alarm Log Database, and the official support entry at Siemens Support ID 109813308 — Working with the WinCC OLE DB Provider.

Solution: Querying the ALG Database Directly

Read the comment column from the alarm logging database view instead of trying to access it as a property of the iterated LoggedAlarmStateResult. The runtime OLE DB provider accepts the same SQL the SQL Server Management Studio would, so a single SELECT against dbo.AlgView (or the version-specific view) returns the full alarm row including the comment text. The general read pattern is:

  1. Resolve the active catalog (runtime or archive) and build the connection string.
  2. Open an ADODB connection against the WinCCOLEDBProvider.
  3. Execute a SELECT that returns the comment column (typically Comment or CommentText) along with the alarm state identifiers.
  4. Iterate the resulting recordset and write rows to the CSV file.
  5. Filter on Comment IS NOT NULL AND Comment <> '' to avoid populating the CSV with empty comment cells for the non-comment states of the same alarm.
Field name variability: the comment column is named Comment in WinCC V7.0 through V7.3, and renamed to CommentText in WinCC V7.4 and later (including V7.5 and V8.0). TIA Portal WinCC Professional uses OperatorComment. Verify by running SELECT TOP 1 * FROM dbo.AlgView in SQL Server Management Studio against the live runtime database before committing to a field name.

Implementation: Complete VBScript for CSV Export

The following VBScript is intended for execution from a WinCC scheduled action, a button event, or directly from the WinCC script editor. It enumerates the available runtime and archive catalogs, queries the alarm logging view for the requested time window, and writes the rows — including the comment — to a CSV file. Replace the catalog timestamp enumeration with a fixed string only if you are exporting historical data after a project restart; for live runtime data, always enumerate.

' WinCC VBScript — Export alarm log with operator comments to CSV
Option Explicit

Dim conn, rs, catRS, fso, file, sLine
Dim providerSQL, sConn, sCSVPath, sSQL
Dim startTime, endTime, catalogName, catalogPrefix
Dim colTime, colMsgNr, colState, colUser, colComment, colComp, colInst, colCounter

startTime  = "2024-01-15 00:00:00.000"
endTime    = "2024-01-16 00:00:00.000"
providerSQL = "Provider=WinCCOLEDBProvider.1;Data Source=.\WinCC"

Set conn = CreateObject("ADODB.Connection")
Set fso  = CreateObject("Scripting.FileSystemObject")

' Enumerate runtime and archive catalogs to find one covering the window
Set catRS = CreateObject("ADODB.Recordset")
conn.Provider = "WinCCOLEDBProvider.1"
conn.Properties("Data Source") = ".\WinCC"
conn.Open "", ""
Set catRS = conn.Execute("SELECT Catalog FROM MASTER.DBO.Catalogs WHERE Catalog LIKE 'CC[_]%' ORDER BY Catalog")

catalogName = ""
Do While Not catRS.EOF
    If InStr(catRS.Fields("Catalog").Value, "CC_OpenArch_") > 0 Then
        catalogName = catRS.Fields("Catalog").Value
    End If
    catRS.MoveNext
Loop
catRS.Close

If catalogName = "" Then
    MsgBox "No archive catalog found covering the requested window.", vbCritical
    conn.Close
    Set conn = Nothing
    WScript.Quit 1
End If

sConn = providerSQL & ";Catalog=" & catalogName
Set conn = CreateObject("ADODB.Connection")
conn.Open sConn

' Query alarm view — adjust CommentText/Comment per WinCC version
sSQL = "SELECT Time, MS, MsgNr, State, ComputerName, Instance, Counter, UserName, CommentText " & _
       "FROM dbo.AlgView " & _
       "WHERE Time BETWEEN '" & startTime & "' AND '" & endTime & "' " & _
       "AND CommentText IS NOT NULL AND CommentText <> '' " & _
       "ORDER BY Time ASC, MS ASC, Counter ASC"

Set rs = conn.Execute(sSQL)

sCSVPath = "D:\WinCC_Export_&" & Replace(Replace(Replace(FormatDateTime(Now, 2), "/", "-"), ":", "-"), " ", "_") & ".csv"
Set file = fso.CreateTextFile(sCSVPath, True, True)  ' True = Unicode

' Header
file.WriteLine "Timestamp,MsgNr,State,UserName,Comment,ComputerName,Instance,Counter"

Do While Not rs.EOF
    sLine = FormatDateTime(rs.Fields("Time").Value, vbGeneralDate) & "." & Right("000" & rs.Fields("MS").Value, 3) & "," & _
            rs.Fields("MsgNr").Value & "," & _
            rs.Fields("State").Value & "," & _
            Chr(34) & Replace(rs.Fields("UserName").Value, Chr(34), Chr(34) & Chr(34)) & Chr(34) & "," & _
            Chr(34) & Replace(rs.Fields("CommentText").Value, Chr(34), Chr(34) & Chr(34)) & Chr(34) & "," & _
            rs.Fields("ComputerName").Value & "," & _
            rs.Fields("Instance").Value & "," & _
            rs.Fields("Counter").Value
    file.WriteLine sLine
    rs.MoveNext
Loop

file.Close
rs.Close
conn.Close

Set file = Nothing
Set rs = Nothing
Set conn = Nothing
Set fso = Nothing

MsgBox "Export complete: " & sCSVPath, vbInformation

The line AND CommentText IS NOT NULL AND CommentText <> '' is the key behavioural change from the failing script — it restricts the export to only those alarm state rows where the operator actually entered a comment, which is normally the Acknowledged (State = 3) state. If the report must include the alarm row even when no comment is present, remove the predicate and accept an empty cell in the Comment column.

SQL Query Patterns for Alarm-Comment Joins

When the export is a full alarm log (not filtered to comments only) and the comment needs to be associated with the originating alarm regardless of the state row on which it was entered, the typical pattern is a self-join on the alarm state key. The canonical state key is the tuple (MsgNr, Time, MS, ComputerName, Instance, Counter). Because the comment row is the acknowledged state of the same alarm, a sub-select on the same view with State = 3 returns the comment in the originating Came In row.

SELECT
    a.Time, a.MS, a.MsgNr, a.State, a.UserName, a.ComputerName, a.Instance, a.Counter,
    (SELECT TOP 1 b.CommentText
       FROM dbo.AlgView b
      WHERE b.MsgNr        = a.MsgNr
        AND b.ComputerName = a.ComputerName
        AND b.Instance     = a.Instance
        AND b.State        = 3) AS OperatorComment
FROM dbo.AlgView a
WHERE a.Time BETWEEN '2024-01-15 00:00:00' AND '2024-01-16 00:00:00'
ORDER BY a.Time ASC, a.MS ASC, a.Counter ASC

For high-volume archives, a CTE or window function variant avoids the correlated sub-select penalty. The same pattern applies in TIA Portal WinCC Professional, but the view is typically dbo.AlgView under the MS SQL Server instance named .\WinCCRT, and the comment column is named OperatorComment.

TIA Portal WinCC Professional Differences

WinCC Professional (part of the TIA Portal Engineering framework) uses the same underlying SQL Server storage but renames the views, fields, and the SQL Server instance. The key differences for the comment export path are summarised below.

Aspect WinCC V7.x WinCC Professional (TIA Portal)
SQL Server instance .\WinCC .\WinCCRT (runtime), .\WinCC (config)
Runtime catalog prefix CC_<Project>_ CC_<Project>_
Archive catalog prefix CC_OpenArch_ CC_OpenArch_
Alarm view dbo.AlgView dbo.AlgView
Comment column (≥ V7.4 / V15) CommentText OperatorComment
OLE DB provider WinCCOLEDBProvider.1 WinCCOLEDBProvider.1
Add comment API AlarmLogging.AddComment(...) HMIRuntime.Alarms (C# / VB via Openness)

For panel-based systems (WinCC Comfort / Advanced on TP700 / TP1500 / TP2200), alarm comments are stored in a proprietary log file and are not exposed through a SQL interface — they must be exported through the panel's USB / FTP / DataLogging export, as documented in the Pro-face alarm log export guide (analogous flow for the Siemens Comfort panels). The approach described in this article applies to the PC-based runtime only.

CSV File Structure, Encoding, and Verification

The exported CSV must be valid against RFC 4180 to be imported by Excel, Power BI, or the historian downstream. The minimum requirements are:

  • Encoding: UTF-16 LE (BOM) when opened with CreateTextFile(..., True) in VBScript — Excel will detect the BOM and display non-ASCII operator names correctly. For UTF-8 output, write a BOM manually (Chr(239) & Chr(187) & Chr(191)) before the header.
  • Delimiter: comma; the script above uses Chr(34) quotes for fields containing the delimiter, embedded quotes, or line breaks.
  • Embedded quotes inside operator comments must be escaped by doubling: He said "ack" becomes ""ack"" inside the quoted CSV field.
  • Multi-line operator comments must remain inside the same quoted CSV field; Replace(comment, vbCrLf, " ") collapses them if downstream tools cannot handle embedded newlines.
  • Header row: Timestamp,MsgNr,State,UserName,Comment,ComputerName,Instance,Counter.

Verification checklist after running the script:

  1. Open the resulting CSV in Excel — non-ASCII user names must render without ü artefacts.
  2. Confirm all alarms in the requested window are present (count rows, compare to the AlarmControl).
  3. Confirm every alarm that was acknowledged with a comment in the AlarmControl has a non-empty Comment column.
  4. Confirm the Time column matches the local time set in the WinCC project (WinCC stores UTC by default; convert in the SELECT or in the script if local time is required).

Troubleshooting Matrix

Symptom Likely Cause Corrective Action
Object doesn't support this property or method on loggedAlarmState.Comments Property name is wrong or not present in the iterated LoggedAlarmStateResult Use Comment (V7.0–V7.3) or CommentText (V7.4+) and read via SQL
Empty Comment column for alarms that have comments in the AlarmControl Script is iterating on the Came In state; comment lives on the Acknowledged state Filter on State = 3 or use the correlated sub-select join in the SELECT
Catalog not found error after project restart Hard-coded CC_<Project>_<timestamp> catalog name no longer exists Enumerate catalogs at script start or query the CC_OpenArch_ prefix for historical ranges
Login failed for user 'sa' WinCC runtime database requires Windows authentication, not SQL authentication Use Integrated Security=SSPI in the connection string (or omit user/password in OLE DB provider call)
Non-ASCII characters render as ü in Excel CSV written as ANSI, not UTF-8 / UTF-16 with BOM Open file with CreateTextFile(path, True, True) for UTF-16 LE, or write a UTF-8 BOM
Script returns zero rows even though comments exist Wrong catalog (operator entered comment on a different server or in a closed segment) Query MASTER.DBO.Catalogs and try each CC_OpenArch_ catalog in turn
Column name 'CommentText' is invalid WinCC version is V7.3 or earlier, where the column is named Comment Verify the actual column with SELECT TOP 1 * FROM dbo.AlgView in SSMS
Performance: export takes > 60 s for a 24 h window Full scan of the alarm view without an index hint Restrict the Time predicate to the smallest possible window; do not export the full archive in one query

Best Practices for Production Deployments

  • Schedule the export, do not run it interactively. Trigger the VBScript from a WinCC cyclic action or a Windows scheduled task that runs cscript.exe //nologo export.vbs. This keeps the export off the operator client and avoids contention with the AlarmControl.
  • Always enumerate catalogs at run time. Hard-coding the catalog name is the most common cause of overnight script failures because WinCC recreates the runtime catalog on project start.
  • Write to a timestamped file, never overwrite. Operators auditing the previous shift will need the file with the date and time of generation, not the latest snapshot.
  • Keep the time window narrow. A 24 h export of a high-volume plant can exceed several hundred thousand rows. If a full day is required, consider exporting state by state (Came In only, Acknowledged only) and joining offline.
  • Validate against the live AlarmControl. The AlarmControl is the ground truth. If the CSV disagrees with what the operator sees, the CSV is wrong — the database is read-only by design.
  • Do not modify the dbo.AlgView view directly. WinCC recreates this view on project start. Any custom view must be created in a separate schema.

Frequently Asked Questions

Why does LoggedAlarmStateResult not expose a Comments property in WinCC V7?

The LoggedAlarmStateResult class is bound to the runtime OLE DB provider's result schema, which exposes the state columns MsgNr, State, Time, MS, UserName, ComputerName, Instance, and Counter. The operator comment is stored in a column named Comment in WinCC V7.0–V7.3 or CommentText from V7.4 onwards, and must be read by querying the underlying dbo.AlgView directly through the OLE DB provider with a SELECT statement rather than accessed as a property of the iterated result object.

What is the correct OLE DB connection string for the WinCC V7 runtime alarm database?

Use Provider=WinCCOLEDBProvider.1;Catalog=CC_<ProjectName>_<YYYY-MM-DD>_<HH-MM-SS.SSS>;Data Source=.\WinCC for live data, or Catalog=CC_OpenArch_<YYYY-MM-DD>_<HH-MM-SS.SSS> for archived segments. The catalog name must be enumerated at runtime via SELECT Catalog FROM MASTER.DBO.Catalogs because it changes every project restart.

How do I add a comment to a WinCC alarm from a VBScript?

Use the AlarmLogging COM object method AddComment(lMsgNr, lState, lTime, lMs, sComputerName, sInstance, lCounter, sUserName, sComment). The state key fields (MsgNr, Time, MS, ComputerName, Instance, Counter) must match the state row the comment is being attached to. UpdateComment() and DeleteComment() are also available on the same interface for lifecycle management of the comment.

Why is the Comment column empty for some alarms that show comments in the AlarmControl?

The comment is stored only on the alarm state row where the operator entered it — typically the Acknowledged state (State = 3). The Came In (State = 1) and Went Out (State = 2) rows for the same message have an empty comment column by design. To export comments alongside the originating alarm, use the correlated sub-select in the SQL query that joins CommentText from the matching State = 3 row by the state key tuple.

Does the same approach work for TIA Portal WinCC Professional and for panel-based Comfort / Advanced panels?

Yes for WinCC Professional — the SQL Server instance is .\WinCCRT and the comment column is named OperatorComment, but the OLE DB provider, the dbo.AlgView view, and the MASTER.DBO.Catalogs enumeration pattern are unchanged. For Comfort / Advanced panels (TP700, TP1500, etc.) the alarm log is stored in a proprietary file and there is no SQL interface — the export must go through the panel's DataLogging export. The flow is documented in the Pro-face alarm log export guide, which uses the same conceptual flow for the Siemens Comfort/Advanced panel family.

Where is the Siemens official documentation for the WinCC OLE DB provider and the comment field?

The primary reference is the WinCC Information System section Working with WinCC > ANSI-C and VBScript in WinCC > OLE DB Provider for WinCC, and the running support entry is Siemens Support ID 109813308. The SQL schema of the runtime database can be inspected directly via SQL Server Management Studio connected to the .\WinCC instance while the runtime is active.

Back to blog