IMD SolutionComputing LibraryShop main store

Explainer

Why a WinCC scheduled script exports snapshots, not archive history

Edge computing and IIoT Published 7 min read By IMD Solution engineering team

Short answer

A scheduled WinCC script that reads current tag values writes fresh snapshots stamped with the execution time; it does not export tag-logging or alarm-logging history. Copying history needs the product's supported archive query interface plus a checkpoint, so decide first whether you copy history or sample current values.

On this page
  1. What does a scheduled WinCC script actually export to SQL Server?
  2. How do you get real tag and alarm history out of WinCC?
  3. What must the destination schema store for history versus snapshots?
  4. How does the DSN and runtime account fit in?
  5. How do you schedule a history copy without gaps or duplicates?
  6. What happens when the transfer fails at 3 a.m.?
  7. So which design should you build?
  8. Questions asked

A scheduled WinCC script that reads current tag values and inserts them into SQL Server produces new snapshots stamped with the execution time, not a copy of the tag-logging or alarm-logging archive. If you need history, use the product's supported archive query interface and copy records with a checkpoint. Decide first which of the two datasets you are building, because the source interface and the acceptance test differ.

What does a scheduled WinCC script actually export to SQL Server? #

It exports snapshots: the tag values read at the moment the script runs, written with the time of that execution. It does not retrieve records already stored by tag logging or alarm logging. The tag archive holds recorded process values with their original timestamps; the alarm archive holds message events and their transition information. A script that reads a tag's current value creates a new sample, and a script that reads an alarm's current state cannot reconstruct earlier transitions. If a value changed twice between two executions, only the value at execution time arrives in the destination table.

The commonly copied recipe, install SQL Server, create a database and table from a script, read tags, and run on a schedule, therefore builds a snapshot database. That is a valid design for periodic reporting, but it must be labeled as such: the rows represent the sampling schedule, not archive history.

How do you get real tag and alarm history out of WinCC? #

Through the archive query interface the installed product documents, not through tag reads. Siemens documents that the WinCC archive data stored in the internal SQL database is accessible to external applications through its archive access interface, and the TIA documentation describes querying archive data with an OLE DB based provider where queries are forwarded to the database by a command object. Identify the installed WinCC product, version and runtime environment first, because products and versions differ in scripting and archive access mechanisms, then use the installed documentation to select the supported interface for tag history and for alarm history separately.

For a multi-tag query, know how the result is shaped before you design destination columns; a WinCC multi-tag query returning rows instead of value columns changes the table design, and that row-per-tag behavior is covered in a related piece on why a WinCC multi-tag query adds rows, not value columns. Treat the connection to your external SQL Server as a second, separate connection: archive access and destination writes are two distinct operations, and a successful SQL Server connection proves destination access, not archive access.

What must the destination schema store for history versus snapshots? #

Define the row's meaning before choosing its columns. A process-value row needs source identity, source timestamp, value and the available quality information; an alarm-event row needs enough fields to distinguish the alarm and the event transition. Keep the original event timestamp in its own column, separate from the time the destination accepted the row. For snapshots, the source timestamp is by definition the execution time, so one time column is enough, but state that in the table design.

A duplicate-prevention key must represent a unique source record. A timestamp alone can collide when several tags or alarms share a time, so design the key from fields that actually distinguish records, for example tag identity plus source timestamp at full precision. Define whether stored times are UTC or local time, and keep the source precision.

Test the schema with representative rows: insert a numeric value and an alarm message through a test connection and confirm both fit their columns without truncation or conversion. Then insert the same uniquely identified record twice and confirm the destination rejects or deliberately ignores the duplicate.

How does the DSN and runtime account fit in? #

A data source name is an ODBC connection definition that identifies a database driver and connection settings, and you configure it only when the chosen script connection uses ODBC; other providers carry their own connection configuration. Match the driver architecture to the process that executes the script, because a connection tested from an interactive desktop session can differ from the one the runtime process opens. A user-scoped DSN may be invisible to a different runtime account, so confirm the runtime execution identity resolves the same driver and server instance used during commissioning.

Provision the database objects once with an administrative deployment account, then give the runtime account only the permissions its transfer needs: insert on the destination tables, nothing more. Creating the database inside a recurring collection script couples data collection to administrative privileges; when a repair or an obsolete host makes replacement the better move, a fanless mini PC is the natural host for such a gateway, but the account model stays the same. Test connectivity from the WinCC runtime computer with the selected driver, then repeat the insert test under the actual runtime identity and confirm it writes without database-creation rights.

How do you schedule a history copy without gaps or duplicates? #

Scheduling controls when a transfer executes, not which records belong to it. Historical copying needs a checkpoint, a stored position marking the last successfully transferred source record, and you advance it only after the corresponding destination writes commit. Otherwise a failed write makes the next execution skip records permanently. The run then proceeds in a fixed sequence: read the checkpoint, retrieve a small bounded source interval, map the returned fields to destination columns with parameterized commands, commit the batch, persist the checkpoint. Prevent overlapping executions so only one run owns a given checkpoint update.

Worked example of the sizing decision: schedule a run every 5 minutes and copy at most 5 minutes of source records per batch. With a tag logged every 1 second and 20 tags in the copy set, one batch is 20 tags times 300 s, giving 6000 rows of at most about 50 bytes each, roughly 300 kB per batch. A 100 Mbps plant network moves that in well under a second, so the schedule interval, not bandwidth, bounds the batch; if the archive query itself takes longer than the interval, lengthen the interval rather than letting executions overlap. After a long outage, copy several bounded batches in sequence from the old checkpoint rather than one unbounded interval.

The acceptance test that separates history from snapshots is simple: request an interval containing a known historical value or alarm event and confirm the interface returns the historical record even though the current value or alarm state differs. For a snapshot design, change a test tag between two executions and confirm the destination receives only the values observed at execution time.

What happens when the transfer fails at 3 a.m.? #

Database outages and runtime restarts must not silently create gaps. Log connection failures, source-query failures, destination-write failures and checkpoint failures as separate categories, and capture the actual diagnostic message from the failing component rather than treating everything as a scheduling problem. Retries can repeat records written before an interruption, so make writes idempotent: repeating the same source record must leave one logical row, which the duplicate key above already guarantees. A failed batch leaves the checkpoint at its last committed position, and the next successful run resumes exactly there. This checkpoint discipline is the same principle that separates working archive paths from dead ends, as in why WinCC tag data never reaches Process Historian 2014 and transferring old WinCC tag logging data to Process Historian.

One more limit to respect: never write into the databases WinCC manages internally. Changing an application's internal schema bypasses its supported interfaces and can disrupt the application.

So which design should you build? #

Build the snapshot script if the destination is a reporting database of periodic current values and nobody will ever ask it what happened between executions. Build the archive copy, with the documented query interface, a duplicate key and a checkpoint, if the requirement says export tag logging and alarm logging, if the data must survive a runtime restart, or if anyone will trend the destination data later. For alarm history specifically there is no snapshot shortcut at all: alarm transitions exist only in the alarm archive, so copying that archive is the only path. In both designs, keep the internal WinCC databases untouched and grant the runtime account the minimum the transfer needs; for the wider question of whether a full historian belongs in the picture at all, see do you need a historian or just an OPC tag server?.

Questions asked

Can I read the WinCC tag archive with an ODBC DSN?

Not as a plain SQL Server database. The tag and alarm archives are managed internally by WinCC, and the documented access path is the product's archive query interface, which for the installed version may be an OLE DB based provider. Use the ODBC DSN only for the external SQL Server destination.

What happens to my data if the SQL Server is down during a scheduled run?

For snapshot scripts, the samples taken during the outage are lost and cannot be regenerated, because the script never stored them anywhere else. For history copying with a checkpoint, the run simply stops, and the next successful run resumes from the last committed position once the server returns.

Should the script create the database and tables itself?

No. Create the destination database and tables once with an administrative account, then give the runtime account only insert and select rights on those tables. Creating objects inside a recurring script couples data collection to administrative privileges and hides schema changes inside runtime code.

How large should each history copy batch be?

Keep it small enough to finish within one scheduling interval: for example, with a run every 5 minutes, copy at most about 5 minutes of source records per batch.

Does a successful SQL Server insert prove the archive was read correctly?

No. The insert proves the destination connection and permissions work. Archive correctness is proven separately by requesting an interval with a known historical value or alarm event and confirming the returned record keeps its source timestamp even when the current tag value differs.

Keep reading

  • Troubleshooting

    Why TLGGetArchiveDataEx returns only OS server data

    TLGGetArchiveDataEx and the WinCC OLE DB provider both read the archive belonging to the machine they run on, so a PCS 7 OS Client at v8.0 SP2 returns OS server data and cannot return Process Historian 2013 Upd7 data. Commission Information Server against the Process Historian, then validate one known tag over a historian-only interval before trusting any export.

    Edge computing and IIoT

  • How-to

    How to log Ignition tags every 15 minutes to a database

    To capture Ignition tag values on a strict 15-minute schedule, use a scheduled SQL Bridge transaction group that inserts a snapshot row into a database table, then point the report's query at that table. The tag historian is deadband-driven and stores asynchronously, so it cannot be set to one fixed 15-minute timestamp.

    Edge computing and IIoT

  • Troubleshooting

    Ignition historian logs memory tags but not OPC tag changes

    Memory tags record because their history subscription was created fresh; the migrated OPC tags carry a stale recording subscription that a storage-provider field edit alone does not rebuild. Fix one tag first: disable history, save, re-enable history with the production provider, and save again, then verify with one safely forceable fault before batching across the remaining tags.

    Edge computing and IIoT

PI Server event queue flush period and seconds-late archive data