Overview: WinCC Data Export Without Add-on Software
Siemens SIMATIC WinCC stores runtime process data — including tag logging (trends), alarm logging, and audit trails — in a Microsoft SQL Server database. Exporting this data to CSV or XLS for reporting, audit, or analysis is a frequent requirement in plant-floor applications. WinCC 7.0 SP2 and later ship with built-in export routines, but legacy systems running WinCC V6.0 / V6.2 require a script-based approach using the WinCC OLE-DB Provider or the SQL Server back-end via ADO.
This reference covers four export strategies, ordered from simplest to most flexible:
- Built-in export in WinCC 7.x Online Trend / Online Table controls.
- Built-in code snippet "Export alarm log as CSV" in WinCC Unified.
- VBScript with ADO / OLE-DB Provider in WinCC 6.x and WinCC 7.x.
- C script using the WinCC OLE-DB API for high-frequency or long-window exports.
All four approaches use only the base WinCC installation; no WinCC/Connectivity Pack license, no Process Historian, and no Information Server is required.
WinCC OLEDB Provider) is installed with every WinCC Runtime license. The Connectivity Pack is a separate option for OPC UA / XML / OLE-DB server exposure; it is not required for the client-side export scripts described here. See the WinCC V7.5 SP2 manual entry "Data exchange via OLE DB" for the formal licensing statement.
Prerequisites
| Component | Required Version / Configuration |
|---|---|
| WinCC Runtime | V6.0 SP3+ for ADO method, V7.0 SP2+ for built-in, V16+ (Unified) for snippet method |
| SQL Server back-end | MS SQL Server 2005 (WinCC 6.0), 2008 R2 (WinCC 7.0–7.3), 2014 (WinCC 7.4), 2017 (WinCC 7.5), 2019 (WinCC 8.0) |
| WinCC OLE-DB Provider |
WinCCOLEDBProvider.dll (registered at install) |
| WinCC Data Source Name | Default: CC_System_19:15:30:00 (timestamp varies per project) |
| User permission | Runtime editor rights to add buttons / scripts; db_owner is not required — db_datareader on WinCC database is sufficient |
| Target path | Local drive or UNC path with write access for the WinCC Runtime user |
Method 1 — Built-in Export in WinCC 7.x Online Controls
WinCC 7.0 SP2 introduced a native export toolbar on WinCC Online Trend Control and WinCC Online Table Control. No scripting is needed; the operator clicks the export icon and chooses CSV or XLS.
Step-by-step
- Open the Graphics Designer and select the Online Table or Online Trend control.
- In the configuration dialog open Toolbar → Elements and enable "Export data".
- Configure the export format in the control properties:
Export → File Type = CSVorXLS. - Set the Export Directory (default: project path) and the Export File Name pattern, e.g.
@[email protected]. - Compile, activate Runtime, and test the toolbar export button.
The exported CSV layout for tag logging columns is:
TimeStamp;VariableName;VariableValue;Quality;Flags
2024-03-15 08:12:01.234;Motor1_Temp;72.6;Good;0
2024-03-15 08:12:02.234;Motor1_Temp;72.7;Good;0
...
For alarm logs the layout includes TimeStamp, MsgState, MsgNumber, MsgClass, MsgText, .... The control writes a UTF-8 file with ; delimiter by default — change to comma in Language & Region on the operator station if required.
Method 2 — Built-in Snippet in WinCC Unified (V16 / V17 / V18)
WinCC Unified includes a ready-made JavaScript snippet that exports the alarm log to CSV. The function is documented in the official Siemens Logging programming guide.
Reference: Configuring Logging for SIMATIC WinCC Unified Systems (Siemens Support, attachment 109782859, V1.0 EN).
Implementation outline
- In TIA Portal, open the Unified HMI project.
- Select HMI Runtime → Alarm logging in the project tree.
- Open the Scripts editor and add the "Export alarm log as CSV" code snippet.
- Bind the snippet to a button event:
HMIRuntime.AlarmLogging.Export(...). - Specify the target path, e.g.
"C:\\Export\\Alarms_<DateTime>.csv".
Minimal Unified JavaScript excerpt:
// Triggered by a button "Export"
export async function Export_Alarms_OnClick(item) {
const path = "C:\\Export\\Alarms_" + new Date().toISOString().replace(/[:.]/g,'-') + ".csv";
const filter = { StartTime: new Date(Date.now() - 86400000), EndTime: new Date() };
await HMIRuntime.AlarmLogging.GetLoggedAlarms(filter)
.then(alarms => {
let csv = "TimeStamp;MsgState;MsgClass;MsgText\n";
alarms.forEach(a => {
csv += `${a.TimeStamp};${a.StateName};${a.ClassName};"${a.Text}"\n`;
});
// Persist via HMIRuntime.FileSystem
HMIRuntime.FileSystem.WriteFile(path, csv, "utf8")
.catch(err => HMIRuntime.Trace.WriteLine("Export error: " + err));
});
}
This snippet uses only standard Unified API calls; no Connectivity Pack license is invoked.
Method 3 — VBScript + ADO / OLE-DB for WinCC 6.x (and 7.x)
This is the classic approach for WinCC V6.0 / V6.2 projects that lack the built-in toolbar. The script connects to the runtime database through the WinCC OLE-DB Provider, executes a SELECT against the archive tables, and writes a CSV using the standard FileSystemObject.
3.1 WinCC Archive Architecture (for SQL queries)
WinCC stores tag logging in database CC_System_<Runtime-Start-Time>. Tables follow the naming convention dbo.TLG_<ArchiveName>_<Index>. Alarm messages are stored in dbo.MS_<n> tables. A reliable way to address a tag's archive without hard-coding table numbers is to query the metadata view:
SELECT archiveName, archiveID, archiveType
FROM dbo.Archive
WHERE archiveName LIKE '%OilTemp%';
The current archive ID is also exposed as the WinCC internal variable @DBS_NP_<ServerPrefix>.
3.2 Connection string
The WinCC OLE-DB Provider exposes both runtime and configuration databases. The runtime connection string is:
Provider=WinCCOLEDBProvider.1;
Catalog=CC_System_19_15_30_00;
Data Source=.\WinCC;
Mode=Read;
Use Mode=Read for export scripts. Mode=ReadWrite should be avoided in operator-triggered scripts.
For direct SQL Server access (bypassing the OLE-DB provider — useful in WinCC 7.x when MS SQL authentication is enabled) the standard ADO connection is:
Provider=SQLOLEDB;
Data Source=.\WinCC;
Initial Catalog=CC_System_19_15_30_00;
Integrated Security=SSPI;
3.3 Complete export VBScript (tag logging, single tag, last 24 h)
Attach the following script to a button on the WinCC screen. The script reads Tagname from a WinCC text field TagToExport and writes a timestamped CSV next to the project folder.
'----------------------------------------------------------------
' WinCC VBS — Export selected tag archive to CSV
' Project : WinCC 6.2 SP3 / 7.5 compatible
' Author : Automation Reference
'----------------------------------------------------------------
Option Explicit
Dim sTagName, sOutFile, sConn, oConn, oRs, oFso, oFile, sLine
sTagName = HMIRuntime.Tags("TagToExport").Read ' e.g. "Motor1_Temp"
sOutFile = "C:\WinCC_Export\" & sTagName & "_" & _
Replace(Replace(Now,":","-"),"/","_") & ".csv"
' --- 1) Resolve archive name from dbo.Archive -----------------
sConn = "Provider=SQLOLEDB;Data Source=.\WinCC;" & _
"Integrated Security=SSPI;Initial Catalog=" & _
GetCurrentRuntimeDB()
Set oConn = CreateObject("ADODB.Connection")
oConn.ConnectionTimeout = 10
oConn.Open sConn
Dim sArchSQL, sArchName
sArchSQL = "SELECT archiveName FROM dbo.Archive " & _
"WHERE archiveName LIKE '%" & Replace(sTagName,"'","''") & "%'"
Set oRs = oConn.Execute(sArchSQL)
If oRs.EOF Then
MsgBox "No archive found for tag " & sTagName, vbCritical
Exit Sub
End If
sArchName = oRs.Fields(0).Value
oRs.Close : Set oRs = Nothing
' --- 2) Query archive rows for last 24 h ----------------------
Dim sSQL
sSQL = "SELECT TimeStamp, RealValue, Quality, Flags " & _
"FROM dbo." & sArchName & " " & _
"WHERE TimeStamp >= '" & Format(DateAdd("h",-24,Now),"yyyy-mm-dd hh:nn:ss") & _
"' ORDER BY TimeStamp ASC"
' --- 3) Stream rows to CSV ------------------------------------
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.CreateTextFile(sOutFile, True, True) ' Unicode
oFile.WriteLine "TimeStamp;RealValue;Quality;Flags"
Set oRs = oConn.Execute(sSQL)
Do While Not oRs.EOF
sLine = oRs.Fields(0).Value & ";" & _
oRs.Fields(1).Value & ";" & _
oRs.Fields(2).Value & ";" & _
oRs.Fields(3).Value
oFile.WriteLine sLine
oRs.MoveNext
Loop
oRs.Close : Set oRs = Nothing
oConn.Close : Set oConn = Nothing
oFile.Close
MsgBox "Export completed: " & sOutFile, vbInformation
'----------------------------------------------------------------
Function GetCurrentRuntimeDB()
' Returns the active CC_System_* database name
Dim oCat, sOut
Set oCat = CreateObject("ADOX.Catalog")
oCat.ActiveConnection = "Provider=SQLOLEDB;Data Source=.\WinCC;Integrated Security=SSPI;"
For Each sOut In oCat.Tables
If Left(sOut.Name,9) = "CC_System" Then
GetCurrentRuntimeDB = sOut.Parent.Name
Exit Function
End If
Next
GetCurrentRuntimeDB = ""
End Function
Key implementation points:
- Database name
CC_System_19_15_30_00is not fixed — it changes each Runtime restart. Resolve it dynamically with the helper function above, or store the active archive ID in an internal tag and read it. - Use
Replace(sTagName,"'","''")to neutralise SQL-injection on user-entered tag names. -
FileSystemObjectwithTrue,Truewrites UTF-16; for UTF-8 useADODB.StreamwithCharset="utf-8". - Do not call
oRs.MoveLaston a forward-only WinCC OLE-DB cursor — it will materialise the whole result set in memory.
3.4 Exporting the alarm log
Alarm messages are stored in the configuration database table dbo.MS_<MsgServerID>. The active message server ID is exposed as internal tag @MSG_SERVER_ID. A typical alarm export query is:
SELECT DateTimeCreated, MsgState, MsgClass, MsgNumber, MsgText
FROM dbo.MS_<MSG_SERVER_ID>
WHERE DateTimeCreated >= '2024-03-15 00:00:00.000'
ORDER BY DateTimeCreated;
To find the live table name dynamically:
SELECT TOP 1 TableName FROM dbo.MS_ServerList
The VBScript wrapper around the query is identical to the tag-logging example; just replace the SELECT statement and the column list.
Method 4 — C Script (ANSI-C) for High-Performance Export
For exports exceeding one million rows or for cyclic background dumps, ANSI-C provides the lowest overhead. The WinCC C-API exposes DMGetVariable... family of functions and the OLE-DB can be used through COM.
Skeleton C-script (compile under WinCC C-Editor):
#include "apdefap.h"
void OnExportTrigger(char* lpszPictureName, char* lpszObjectName)
{
HRESULT hr;
IDBInitialize* pIDB = NULL;
IDBSession* pSession = NULL;
ICommand* pCmd = NULL;
IRowset* pRowset = NULL;
// Build connection string programmatically (runtime DB resolved via DMGetProject)
char szConn[512] = "Provider=WinCCOLEDBProvider.1;Catalog=<DB>;Data Source=.\WinCC;Mode=Read;";
hr = CoCreateInstance(CLSID_WINCC_OLEDB, NULL, CLSCTX_INPROC_SERVER,
IID_IDBInitialize, (void**)&pIDB);
if (FAILED(hr)) { printf("CoCreateInstance failed\n"); return; }
pIDB->lpVtbl->Initialize(pIDB, (BSTR)szConn);
// ... get session, command, prepare SQL, execute, fetch rows via IRowset,
// write to file with fopen/fprintf ...
}
The C-script approach bypasses ADO entirely and is recommended when exporting more than 100,000 rows per trigger.
Cross-Method Comparison
| Method | WinCC Version | Skill Required | Max Rows / Trigger | License Add-on | Live Status |
|---|---|---|---|---|---|
| Built-in toolbar (Online Control) | 7.0 SP2+ | Configuration only | ≈ 500,000 | None | Active |
| Unified snippet | Unified V16+ | JavaScript (TIA) | ≈ 250,000 | None | Active |
| VBScript + ADO / OLE-DB | 6.0 SP3 – 8.0 | VBScript + SQL | ≈ 2,000,000 | None | Active |
| C script + OLE-DB | 6.0 – 7.5 | ANSI-C / COM | ≥ 5,000,000 | None | Active |
File Naming and Storage Conventions
Use a fixed prefix plus a UTC timestamp to avoid name collisions when multiple operators export simultaneously:
C:\WinCC_Export\
├─ Tag\Motor1_Temp_2024-03-15T08-12-01Z.csv
├─ Alarms\Alarms_2024-03-15.csv
└─ Daily\DailyReport_2024-03-15_0600.csv ' scheduled at 06:00
Add a cyclic cleanup routine in the global script:
' Keep only the last 30 days of CSVs in C:\WinCC_Export
Sub CleanExportFolder()
Dim oFso, oFolder, oFile
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder("C:\WinCC_Export")
For Each oFile In oFolder.Files
If DateDiff("d", oFile.DateLastModified, Now) > 30 Then oFile.Delete True
Next
End Sub
Scheduled Background Export
To produce daily reports without operator action, use the WinCC Scheduler (formerly Time-triggered tasks in V6.0):
- In WinCC Explorer, open Scheduler.
- Create a new task: Function =
ExportDailyReport, Trigger = Daily 06:00. - The exported function should call the same VBScript from Method 3 with a fixed tag list (e.g. all tags in a WinCC tag group).
On Unified, replace Scheduler with a Scheduled task on the HMI runtime — TIA Portal path: Runtime settings → Tasks → Add scheduled task.
Verification Checklist
- Click the export button. Expect a "Export completed" dialog and a non-zero file size.
- Open the CSV in Excel or Notepad. The header row matches the documented column list.
- Row count in the CSV = row count from a manual SQL query against the same table for the same interval.
- No WINCC_OLEDB_ERROR entries in the WinCC diagnostic file
<Project>\Diagnostics\WinCC_Sys_.log. - Unicode/UTF-8 characters in tag names (e.g. °C) render correctly in Excel — choose the correct encoding when opening (Data → From Text/CSV).
Troubleshooting Matrix
| Symptom | Root Cause | Resolution |
|---|---|---|
| "Provider cannot be found. WinCCOLEDBProvider not registered" | Provider DLL not registered on the export client | Run regsvr32 "C:\Program Files\Siemens\Automation\WinCC\bin\WinCCOLEDBProvider.dll" as Administrator |
| SQL query returns 0 rows but WinCC shows values | Time window filter excludes data due to UTC/local mismatch | Use UTC consistently: WinCC stores all timestamps in UTC; convert with DateAdd("h",<offset>,Now)
|
| Export hangs after 10 s | Connection timeout default 15 s; archive has millions of rows | Increase oConn.CommandTimeout = 0 and stream rows in batches of 10,000 |
| CSV opens in Excel with all data in column A | Locale uses comma as decimal separator, but delimiter is ;
|
Switch delimiter to comma via oConn.Execute("SET NOCOUNT ON;") + ADO Stream with explicit LineSeparator = adCRLF
|
| "Login failed for user 'sa'" on SQL connection | WinCC default uses integrated security; SQL auth disabled | Change connection string to Integrated Security=SSPI or enable mixed-mode in SQL Server Configuration Manager |
| VBScript error 800A0E7A — Provider cannot be found | 32-bit VBScript on 64-bit OS without WoW redirection | Use cscript //H:cscript from %windir%\SysWOW64 for diagnostics, or install the 32-bit WinCC client |
| Alarm export empty even though alarms are visible | Wrong message server ID hard-coded | Resolve dynamically with SELECT TOP 1 TableName FROM dbo.MS_ServerList (WinCC 7.3+) |
| File written to project folder, not the specified path | WinCC Runtime runs as SYSTEM or a service user without path rights | Configure the WinCC Runtime service account (Computer Management → Services) to have write permission on the target folder |
Security and Audit Considerations
- Restrict the script-triggered Export Directory to a folder under the WinCC project root — UNC paths introduce UNC-injection risk.
- Do not embed SQL credentials in the VBScript; use
Integrated Security=SSPI(Windows authentication) so the operator's role governs read rights. - Log every export in the WinCC audit trail: insert a record into
dbo.UM_<n>(user-management) or append to a local fileC:\WinCC_Export\ExportAudit.log. - For 21 CFR Part 11 / GxP environments, write the CSV with an MD5 hash footer that can be validated by a downstream LIMS system.
Migrating from WinCC 6.x to 7.x or Unified
The VBScript in Method 3 continues to work on WinCC 7.x. The two changes required are:
- The default SQL Server instance changed from
(local)to.\WinCCin WinCC 7.3; older scripts that use(local)must be updated. - WinCC 7.4 introduced the ASO (Application Server Object) which optimises archive queries — the OLE-DB provider transparently benefits, no script change required.
For migration to WinCC Unified, rewrite the VBScript to JavaScript and replace the ADODB and Scripting.FileSystemObject calls with the Unified HMIRuntime.AlarmLogging, HMIRuntime.Tag, and HMIRuntime.FileSystem APIs. The CSV structure remains identical, simplifying downstream parsers.
Alternative: Excel Direct (XLS, Native Format)
For analysts who need a real .xls rather than CSV, two options exist without additional software:
-
Excel ODBC — Install the WinCC OLE-DB Provider on the analyst workstation, then in Excel Data → Get Data → From Other Sources → From ODBC and select the
WinCCOLEDBdata source. Refresh on demand. -
XML Spreadsheet 2003 — Generate a CSV, then use a small VBScript wrapper that emits an
.xmlfile with the<?xml version="1.0"?>declaration and<Workbook><Worksheet><Row>... structure. Excel opens this format natively. No Office license is required on the WinCC station.
Summary
WinCC export without extra software is fully supported across all current Siemens HMI versions. The choice between the four methods depends on WinCC version, required row count, and operator skill. For the legacy WinCC 6.x base referenced in the original query, the VBScript/ADO/OLE-DB pattern (Method 3) is the canonical answer and matches the official Siemens FAQ entry 39040079 on Siemens Industry Online Support. Modern WinCC 7.x and Unified systems provide the same capability through built-in toolbar actions and ready-made code snippets, eliminating the need for any custom scripting in the common case.
Can I export WinCC 6.0 trend data to CSV without buying the Connectivity Pack?
Yes. The WinCC OLE-DB Provider is included in every Runtime install. Use a VBScript button that opens an ADO connection to Provider=WinCCOLEDBProvider.1;Catalog=CC_System_<runtime>;Data Source=.\WinCC;Mode=Read, runs a SELECT against the dbo.TLG_<archive> tables, and writes the rows to a file with Scripting.FileSystemObject. See Method 3 above for the full script.
What is the difference between the WinCC OLE-DB Provider and the Connectivity Pack?
The OLE-DB Provider is a client-side COM DLL installed with the WinCC Runtime. The Connectivity Pack is an optional WinCC server component (license required) that exposes WinCC archives as OPC UA, XML, or OLE-DB servers to remote clients. Operator-station export scripts do not require the Connectivity Pack.
How do I find the current WinCC runtime database name (CC_System_*)?
Resolve it dynamically — the timestamp suffix changes every Runtime restart. Use the ADOX.Catalog helper in Method 3, or read the internal tag @DBS_NP_<ServerPrefix>, or query SELECT name FROM sys.databases WHERE name LIKE 'CC_System%'. Hard-coding the name is the most common cause of "database does not exist" errors after a reboot.
Why are all rows of my CSV in a single Excel column?
Excel uses the Windows regional list separator as the CSV delimiter. On locales where the list separator is ; and the decimal separator is ,, the file uses ; delimiters and Excel parses correctly. If your locale uses , as list separator, change the file extension to .txt and use Excel's import wizard, or rewrite the script to emit \t (tab) delimiters instead.
How can I schedule a daily export automatically in WinCC 7.x?
Use the Scheduler in WinCC Explorer. Create a new task, set the trigger to Daily at the desired time, and point it to a global VBScript function (e.g. DailyExport) that contains the same code as the operator button. On WinCC Unified, configure a Scheduled Task under Runtime settings and bind it to a JavaScript function using HMIRuntime.AlarmLogging / HMIRuntime.FileSystem.